Skip to content
CodeMorph

Download CodeMorph (Beta)

Leave your email, then pick your computer. We'll only write about the beta and new releases.

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.

Download CodeMorph (Beta)

Leave your email, then pick your computer. We'll only write about the beta and new releases.

See how it works

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

Flip every file to TypeScript and silence the errors with ts-nocheck or any. It compiles on day one, and the types are fiction.

Codemods

Automated tools convert files mechanically and insert any and ts-expect-error wherever inference fails. Faster, with the same result.

AI chat, file by file

Paste a file in, get TypeScript back. It looks right until you notice the model invented the shape of every import it could not see.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.

  1. 1Commit everything and make sure your tests pass before you start, so any failure later points at a real change.
  2. 2Install TypeScript and add a tsconfig.json with allowJs, so JavaScript and TypeScript can live side by side during the migration.
  3. 3Measure your baseline: how many type errors your JavaScript already has under checkJs. Progress is measured against it.
  4. 4Convert leaf modules first, then work toward the entry point. Keep files that import each other in a cycle in the same batch.
  5. 5Type third-party packages with the @types packages before converting the files that use them.
  6. 6Raise strictness in steps: loose first, then noImplicitAny and strictNullChecks one at a time, then strict.
  7. 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?
It depends on the size of the codebase and how tangled its imports are. A good plan makes it predictable: you can see how many batches there are and review them one at a time instead of facing one giant change.
Do I have to convert everything at once?
No. With allowJs enabled, JavaScript and TypeScript files can sit side by side. Converting leaf files first, in batches, lets you ship in between.
Should I turn on strict mode from the start?
Usually not. Get every file to TypeScript with a loose configuration, then raise strictness in steps. CodeMorph holds the project to whatever your tsconfig.json says.
Will an AI code migration change how my code behaves?
Conversions are meant to preserve behavior, and the type-check proves the types are consistent. It does not prove behavior is unchanged, so run your own tests after each batch. Running them from CodeMorph is coming soon.
Does my code leave my machine?
Your code goes only to the AI provider you choose, with your own key. Nothing passes through our servers. With a local model through Ollama, nothing leaves your computer.
What does CodeMorph cost, and what does it run on?
CodeMorph is free during the beta. It runs on Windows 10 and 11 and on Macs with Apple Silicon or an Intel chip.

Migrate JavaScript to TypeScript with CodeMorph.

Download the beta, open a project and see your migration plan in under a minute.

Download CodeMorph (Beta)

Leave your email, then pick your computer. We'll only write about the beta and new releases.

Read the docs

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.