Guide
JavaScript to TypeScript migration, done in the right order
Most JavaScript to TypeScript migrations stall halfway. Here is why, what a migration that finishes looks like, and how CodeMorph, an AI code editor for code migration, makes each step checkable.
Windows 10/11 · Free during beta · Bring your own Claude key or use Ollama
Windows may show 'unknown publisher'. Click More info, then Run anyway.
The problem
Why JavaScript to TypeScript migrations stall
Almost every team with a large JavaScript codebase has had the same meeting. Someone makes the case for TypeScript: fewer production bugs, safer refactors, editors that know what a function returns. Everyone agrees, and a migration starts. A few files get converted, tsconfig.json grows a list of exceptions, and a year later the codebase is two languages held together by any.
Conversion was never the hard part. Renaming .js to .ts is trivial, and adding annotations is tedious in a way tools can help with. The hard part is proof: knowing the types describe what the code really does, and that the app still works.
The usual options, and where each one breaks
Rename and suppress
Codemods
AI chat, file by file
Each approach produces TypeScript. None of them can tell you whether it is right, so teams review every file by hand. That review is the stall.
The approach
Order, verify, review: the AI code migration that finishes
A migration that finishes is one where every step is small, checkable and reversible. That comes from three habits.
- 01
Map the dependency graph
Types flow upward through imports. If a model converts a file before the files it imports, it has to guess what those imports return. So start by resolving every import in the project into a dependency graph, including cycles, which have to move together. - 02
Convert leaf files first, in batches
Migrate the files that import nothing local first, then work up toward your entry point, in batches small enough to review in one sitting. Each file is converted against imports that are already TypeScript, so the answer is on the page instead of guessed. - 03
Type-check the whole project after every batch
A file is not done when it parses. It is done when tsc reports zero errors across the project, using your own tsconfig.json. Send the compiler errors back for another attempt, and flag whatever still fails for a human instead of forcing it through with any. - 04
Review every change, and keep a way back
Read each converted file as a diff, accept or reject it, and save a checkpoint before anything changes so one click restores the project exactly. Running your tests and build after each batch is the fourth check, and a good habit even when the tool does not run them for you yet.
Checklist
A JavaScript to TypeScript migration checklist
Use this with any tool, or none.
- 1Commit everything and make sure your tests pass before you start, so any failure later points at a real change.
- 2Install TypeScript and add a tsconfig.json with allowJs, so JavaScript and TypeScript can live side by side during the migration.
- 3Measure your baseline: how many type errors your JavaScript already has under checkJs. Progress is measured against it.
- 4Convert leaf modules first, then work toward the entry point. Keep files that import each other in a cycle in the same batch.
- 5Type third-party packages with the @types packages before converting the files that use them.
- 6Raise strictness in steps: loose first, then noImplicitAny and strictNullChecks one at a time, then strict.
- 7Run tsc --noEmit in CI so the codebase can never slide backwards.
Go deeper
CodeMorph
How CodeMorph does JavaScript to TypeScript migration
CodeMorph is a desktop code editor with this approach built in. Scan & Plan builds the dependency graph and a leaf-first plan in seconds. Batch migration converts each batch against typed imports. Run & Verify type-checks the whole project and sends errors back for repair. Every file arrives as a diff you accept or reject, and a checkpoint is saved first, so Undo all restores your project byte for byte.
You bring your own model key, or run models locally with Ollama. Your code goes only to the AI provider you choose, and nothing passes through our servers. The Morph agent, which answers questions about your changes, and running your tests and build from Run & Verify are coming soon.
Questions about JavaScript to TypeScript migration
How long does a JavaScript to TypeScript migration take?
Do I have to convert everything at once?
Should I turn on strict mode from the start?
Will an AI code migration change how my code behaves?
Does my code leave my machine?
What does CodeMorph cost, and what does it run on?
Migrate JavaScript to TypeScript with CodeMorph.
Download the beta, open a project and see your migration plan in under a minute.
Windows 10/11 · Free during beta · Bring your own Claude key or use Ollama
Windows may show 'unknown publisher'. Click More info, then Run anyway.