NPH
Huy Nguyenhuynp.dev
Cover
Engineering

Migrating to TypeScript - A Survival Guide

Author
Huy Nguyen
May 15, 20248 min

TypeScript has become the industry standard for large-scale JavaScript applications. However, the migration process is often where teams struggle.

The Strict Mode Dilemma

Should you turn on strict mode immediately? In our experience, no. It's better to ramp up strictness over time.

json
// tsconfig.json
{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false, // Start false, enable gradually
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  }
}

Start Small

Don't try to migrate everything at once. Enable allowJs in your tsconfig and migrate file by file.

  1. Rename files: Start with leaf components (components with no dependencies). Rename .js to .tsx.
  2. Fix types: Fix the immediate red squigglies. Use any if you must, but mark it with a TODO.
  3. Strictness: Once 80% of the codebase is migrated, enable strictNullChecks.

Conclusion

Migration is a marathon, not a sprint. Focus on high-impact areas first.

Related articles

Enjoyed this article?

Subscribe to the newsletter to get notified about new posts.