Migrating a JavaScript Codebase to TypeScript
TypeScript allows an incremental migration — plain .js files can
coexist with .ts files in the same project via "allowJs": true.
A common approach:
- Add a
tsconfig.jsonwith"allowJs": trueand"strict": false(loose at first). - Rename files to
.tsone at a time, starting with the most depended-on/foundational ones. - Fix the type errors surfaced in each file as you go.
- Once most of the codebase is converted, gradually enable
"strict": trueand address the additional errors it reveals.
Trying to enable full strict mode on day one of a large migration usually surfaces too many errors at once to be practical.