TickYouOff
Back
🔷

TypeScript Strict Mode Migration

Hard 15 items · 2 hours
testuser's avatar
testuser Published 1 month ago

This checklist guides developers through a safe, incremental migration to TypeScript strict mode. It’s for engineers maintaining a codebase who want to enable strict flags (noImplicitAny, strictNullChecks, strictPropertyInitialization, noImplicitReturns) while migrating files one-by-one with //@ts-nocheck scaffolding.

Progress
0 / 15
  1. Create migration branch and back up tsconfig — Open a new Git branch and save a copy of tsconfig.json to revert if needed.
  2. Run initial full type check (tsc --noEmit) and save error list — Capture current compiler errors so you can measure progress during migration.
  3. Add //@ts-nocheck to files you will migrate later — Temporarily silence type errors per file so you can focus on one file at a time.
  4. Enable noImplicitAny in tsconfig.json — Turn on the flag under compilerOptions to detect implicit any usages.
  5. Fix implicit any errors by adding explicit types — Add parameter and variable types or use 'unknown' before narrowing to specific types.
  6. Run tsc and adjust types iteratively after fixes — Re-run the compiler frequently to catch dependent type errors as you change types.
  7. Enable strictNullChecks in tsconfig.json — Enable to force explicit handling of null and undefined across the codebase.
  8. Audit nullable values and use optional chaining or checks — Add null checks, defaults, or narrow types to safely handle nullable values.
  9. Enable strictPropertyInitialization in tsconfig.json — Require class properties to be initialized or explicitly marked as definite.
  10. Initialize properties in constructors or use definite assignment (!) carefully — Prefer initializing properties; use '!' only when you're certain the value will be set.
  11. Enable noImplicitReturns in tsconfig.json — Detect functions that might exit without returning a value to avoid runtime bugs.
  12. Run incremental file migrations: remove //@ts-nocheck and fix each file — Uncomment a single file, fix all type errors, run tsc, then remove the comment and commit.
  13. Add explicit return types to exported functions and public APIs — Document intent and improve downstream type checking for consumers.
  14. Update lint and CI to enforce strict checks — Enable typescript-eslint rules and run tsc --noEmit in CI to prevent regressions.
  15. Run full type check, remove temporary scaffolding, and merge branch — Run tsc, run tests, remove remaining //@ts-nocheck comments, then merge when green.
Sign in to save
📝 My Notes