Chapter 36: TypeScript in JavaScript Projects (JSDoc)

TypeScript in JavaScript Projects — via JSDoc (very detailed, realistic 2025–2026 perspective)

Imagine the following situation — very common in 2025–2026:

  • You have a medium/large JavaScript codebase (not TypeScript)
  • You want better autocompletion, hover documentation, refactoring safety, type errors before runtime
  • But you cannot / do not want to rename all files to .ts, run build steps, change the CI pipeline, deal with transpilation issues, convince the team to learn TypeScript syntax, etc.

Solution that many teams actually choose todayUse TypeScript’s type checker only as a “smart linter” on plain JavaScript files → Write type information using JSDoc comments → Let VS Code + tsc –noEmit –watch show you red squiggles and suggestions

This approach is officially called “TypeScript in JavaScript with JSDoc” (or “JSDoc-powered TypeScript checking”)

1. How much value can you really get without converting to .ts files?

In 2025–2026 — surprisingly a lot:

Feature Works with JSDoc + .js files? Quality / DX in 2026
Autocompletion inside functions Yes Very good
Hover type information Yes Excellent
Parameter & return type checking Yes Very good
Refactor → rename symbol Yes Good–very good
Find all references Yes Good
“Extract to function” with type preservation Yes Good
Catch property-does-not-exist errors Yes Good
Strict null/undefined checking Partial (requires extra flags) Medium–good
Generics & conditional types Yes (limited but useful) Medium
Full strict mode + noImplicitAny No (almost impossible)

Bottom line in 2026: JSDoc + TypeScript gives you ~60–80% of the value of full TypeScript with ~10–20% of the migration pain

2. Minimal setup (what actually works best in 2026)

package.json

JSON

tsconfig.json — the sweet spot for JSDoc + .js files

JSON

3. Most useful JSDoc patterns (real examples people actually write)

Pattern 1: Basic function typing

JavaScript

Pattern 2: Object shape

JavaScript

Pattern 3: Array of objects

JavaScript

Pattern 4: Import types from other files (very powerful)

JavaScript

Pattern 5: Generic-like behavior (limited but useful)

JavaScript

Pattern 6: Promise / async

JavaScript

4. Quick reference — most useful JSDoc tags in 2026

Tag What it does Most common use-case
@param {Type} name Parameter type Almost every function
@returns {Type} Return type Functions that return values
@typedef Define reusable object shape DTOs, API responses, config objects
@type Inline type for variable When you cannot use @typedef
@template T Generic type parameter Utility functions
@import Import type from another file Cross-file type reuse
@satisfies TS 4.9+ — narrow without widening Config objects, theme tokens
@see Link to documentation Team knowledge sharing

5. Realistic migration path using only JSDoc

  1. Add tsconfig + checkJs: true
  2. Run tsc –noEmit → see hundreds of errors
  3. Start adding @param, @returns, @typedef to high-traffic utility functions
  4. Fix obvious errors (wrong number of arguments, property does not exist)
  5. Gradually add types to more files
  6. When a file feels “ready” → rename to .ts and convert syntax (optional)
  7. Eventually turn on more strict flags

Many teams stop at step 4–5 — they never rename to .ts and stay in “JSDoc TypeScript” mode for years.

6. Pros & Cons — honest 2026 perspective

Pros

  • Zero runtime changes
  • No build step changes
  • Team can adopt gradually (one developer can start)
  • Works with plain .js, .jsx, .cjs
  • Very good VS Code experience
  • Low risk — can remove everything easily

Cons

  • Verbose (lots of comments)
  • No enums, no as const inference, no real generics
  • No satisfies on variables (only on expressions)
  • Refactoring across files sometimes weaker
  • Cannot use full strict mode (noImplicitAny usually stays off)
  • Some third-party libs still need @types/*

7. Your first realistic step today

  1. Add the tsconfig above
  2. Run npx tsc –noEmit → see what complains
  3. Pick one small utility function in your project
  4. Add @param and @returns
  5. Watch VS Code give you better hints immediately
  6. Run tsc –noEmit again → see fewer errors

Any part confusing or most relevant for your current codebase?

Want to:

  • See a full small project before/after JSDoc
  • Compare JSDoc vs full .ts migration effort
  • Learn the most powerful JSDoc + generics tricks
  • Handle JSX + JSDoc in React projects
  • Discuss when to finally switch to real .ts files

Just tell me — we continue from exactly where you need it 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *