0Pricing
TypeScript Academy · Lesson

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

  1. Starting the Migration: allowJs and checkJs
  2. JSDoc Type Annotations as a Bridge
  3. File-by-File Conversion Strategy
  4. Dealing with Untyped Third-Party Libraries
← Back to TypeScript Academy