JSDoc can serve as a full alternative to TypeScript syntax for typing JavaScript codebases without creating any .ts files. The TypeScript compiler understands JSDoc comments, enabling type checking in plain .js files when checkJs is enabled in tsconfig.json. Covered features include @type, @param, @returns, type casting, const assertions, @typedef for type declarations, type importing/exporting, @template for generics, class properties, @implements, @public/@private, and @this. Key limitations are highlighted, especially the lack of non-null assertion support (no @nonnull equivalent), the verbose workarounds required, and the auto-exporting behavior of @typedef. Interop between .js JSDoc modules and .ts TypeScript modules works seamlessly.

12m read timeFrom alexharri.com
Post cover image
Table of contents
JSDocPractical mattersConclusion

Sort: