TS-Migrate是Airbnb(爱彼迎)公司开源的前端工具,可将 JavaScript 代码快速迁移为 TypeScript 代码,节省前端工程师的时间成本,统一开发环境。遵守MIT开源协议。





ts-migrate is a tool for migrating frontend application to TypeScript. Run npx ts-migrate <folder> to convert your frontend application to TypeScript.

ts-migrate is designed around Airbnb projects. Use at your own risk.


Install ts-migrate using npm:

npm install --save-dev ts-migrate

Or yarn:

yarn add --dev ts-migrate


Migrate an entire project like this:

npx -p ts-migrate -c "ts-migrate-full <folder>"

Please note that it may take a long time to do a full migration. You can also migrate individual parts of a project by specifying a subset of sources:

npx ts-migrate-full <folder> /                # specify the project root, and
  --sources="relative/path/to/subset/**/*" /  # list the subset to migrate,
  --sources="node_modules/**/*.d.ts"          # including any global types that the
                                              # migrator may need to know about.

Or, you can run individual CLI commands:

$ npx ts-migrate -- --help

npm run ts-migrate -- <command> [options]

  npm run ts-migrate -- init <folder>       Initialize tsconfig.json file in <folder>
  npm run ts-migrate -- rename <folder>     *Rename files in folder from JS/JSX to TS/TSX
  npm run ts-migrate -- migrate <folder>    *Fix TypeScript errors, using codemods
  npm run ts-migrate -- reignore <folder>   Re-run ts-ignore on a project

* These commands can be passed a --sources (or -s) flag. This flag accepts a relative
path to a subset of your project as a string (glob patterns are allowed). When this flag
is used, ts-migrate ignores your project's default source files in favor of the ones
you've listed. It is effectively the same as replacing your tsconfig.json's `include`
property with the provided sources. The flag can be passed multiple times.

  -h,  -- help      Show help
  -i,  -- init      Initialize TypeScript (tsconfig.json) in <folder>
  -m,  -- migrate   Fix TypeScript errors, using codemods
  -rn, -- rename    Rename files in <folder> from JS/JSX to TS/TSX
  -ri, -- reignore  Re-run ts-ignore on a project

  npm run ts-migrate -- --help                Show help
  npm run ts-migrate -- init frontend/foo     Create tsconfig.json file at frontend/foo/tsconfig.json
  npm run ts-migrate -- rename frontend/foo   Rename files in frontend/foo from JS/JSX to TS/TSX