What is ts-migrate and Why It Exists
ts-migrate is Airbnb's migration tool that exists because manually converting large Java
Script codebases to TypeScript is a nightmare that makes you question your life choices.
Instead of spending months manually rewriting every file, ts-migrate brute-forces your JavaScript into compiling TypeScript.
Core Purpose and Reality Check
Airbnb built this because they had massive JavaScript codebases and converting them by hand would take until the heat death of the universe. The tool follows the "make it compile first, fix the types later" philosophy
- because perfect is the enemy of done, and perfect TypeScript migration is a myth.
At Airbnb, they used this on massive projects and got them compiling quickly.
Does it create beautiful, type-safe TypeScript? Hell no. Does it create TypeScript that actually compiles so you can start getting some benefits while you clean up the mess? Absolutely. [Large codebases](https://github.com/microsoft/Type
Script/wiki/Performance) benefit from gradual migration approaches, and TypeScript adoption statistics show the language's growing popularity in enterprise environments.
How This Thing Actually Works
Plugin-Based Architecture: ts-migrate uses a modular plugin system that you can customize.
The default setup assumes you're using React, which is great if you are and annoying if you're not. The plugins handle PropTypes conversion and other React-specific patterns pretty well.
Codemod Foundation:
Under the hood, it's using codemods (code modification scripts) to systematically transform your JavaScript.
It extracts type information from PropTypes (if you have them), handles [imports/exports](https://developer.mozilla.org/en-US/Web/Java
Script/Reference/Statements/import), and adds type annotations wherever it can figure them out.
The approach is similar to other AST transformation tools like jscodeshift.
"Smart" Type Inference:
The tool tries to infer types from your existing code patterns and Prop
Types definitions. When it can't figure something out (which is often), it falls back to any
types aliased as $TSFixMe
. This is by design
- it's better to have compiling code with
any
types than broken code.
Current Status and Compatibility
The latest version is 0.1.35, published 3 years ago in November 2022.
The package gets decent usage but isn't actively maintained anymore
- last real update was years ago. Works fine with React 17/18, untested with React 19 beta.
The tool generates TypeScript that compiles immediately but creates a mess you'll spend weeks cleaning up. This trade-off
- speed vs. quality
- makes it perfect for teams that need to get TypeScript benefits now while accepting they'll be fixing types for months afterward.
Similar migration strategies are discussed in the TypeScript handbook and migration guides.
ts-migrate gets you compiling Type
Script in 2 hours, but you'll spend 6 months explaining to your team why everything is typed as any
.