JSDoc Type Annotations as a Bridge
Add types to JS files using JSDoc before converting.
JSDoc as a TypeScript Bridge
TypeScript can read JSDoc type annotations in JavaScript files when checkJs: true is enabled. This lets you add types to JS without renaming files.
/** @type {string} */
let name = "Alice"; // TypeScript checks this as string@param and @returns
Annotate function parameters and return types using JSDoc tags.
/**
* @param {string} name
* @param {number} age
* @returns {string}
*/
function greet(name, age) {
return `${name} is ${age}`;
}All lessons in this course
- Starting the Migration: allowJs and checkJs
- JSDoc Type Annotations as a Bridge
- File-by-File Conversion Strategy
- Dealing with Untyped Third-Party Libraries