Skip to content

The Art of Migrating from JavaScript to TypeScript Without Breaking Everything

Migrating a project from raw JavaScript to TypeScript is a common trap for overambitious teams.

2 min read
TypeScript
Migration
JavaScript
allowJs
checkJs
Monorepo

Migrating a project from raw JavaScript to TypeScript is a common trap for overambitious teams. A lot of developers fall into the urge to rename every single .js file to .ts over a single weekend, only to end up drowning in thousands of errors that actually stall the team's progress. An ideal migration should be an organic process, not a massive, energy-draining rewrite.

The key is a gradual, file-by-file migration. But don't just start renaming files blindly. Before you dive in, make sure tsc can check your existing JavaScript files within your CI pipeline by using allowJs: true and checkJs: true. This allows TypeScript to flag issues in your JS code without you having to change the extensions first. It’s a much safer way to keep your builds stable.

If the team isn't ready to convert every file, use JSDoc as a middle ground. Writing type documentation through JSDoc is much lower risk and has a lower cost than forcing a half-baked migration that just frustrates everyone with constant errors. You still get the benefits of type checking without the headache of restructuring your files.

Once checkJs is stable and the team is used to it, you can start converting files to .ts one by one. At this stage, avoid the fatal mistake of turning on strict: true in the same pull request where you're renaming files. That’s a recipe for a code review nightmare.

A more sensible approach is to separate your emit strategy from your strictness strategy. I suggest starting with one small package as a pilot project. If that works, then replicate it elsewhere. Not everything needs to be perfect and incredibly strict on day one.

Ultimately, this migration is about managing risk. The goal is to get the benefits of TypeScript’s typing system without killing your momentum on new features. A successful migration is one that doesn't feel like a disruption to the team's productivity.