Engineering
Migrating to TypeScript - A Survival Guide
Moving a large React codebase from JS to TS can be daunting. Here are the strategies we used to migrate 50k lines of code without halting feature work.
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.
// 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.
- Rename files: Start with leaf components (components with no dependencies). Rename
.jsto.tsx. - Fix types: Fix the immediate red squigglies. Use
anyif you must, but mark it with a TODO. - 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
Related tools
Enjoyed this article?
Subscribe to the newsletter to get notified about new posts.