typescript-migration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTypeScript Migration
TypeScript 迁移指南
Authoritative migration guide for TypeScript 5.x → 6 → 7 (native Go port). Sourced from Microsoft's official announcements.
本指南是TypeScript 5.x → 6 → 7(原生Go移植版)的权威迁移手册,内容源自微软官方公告。
Status
状态
- Skill Status: Production Ready
- Last Updated: 2026-07-09
- TS 6.0 Released: 2026-03-17 (Final) — last JavaScript-based release
- TS 7.0 Released: 2026-07-08 — native Go port ("Corsa"), stable
- Authoritative Sources:
- TS 7.0 release: https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/
- TS 6.0 beta: https://devblogs.microsoft.com/typescript/announcing-typescript-6-0-beta/
- TS 6 → 7 diff tracker: https://github.com/microsoft/typescript-go/blob/main/CHANGES.md
- ts5to6 tool: https://github.com/andrewbranch/ts5to6
- 技能状态:已就绪可用于生产环境
- 最后更新:2026-07-09
- TS 6.0 发布:2026-03-17(正式版)—— 最后一个基于JavaScript的版本
- TS 7.0 发布:2026-07-08 —— 原生Go移植版(代号"Corsa"),已稳定
- 权威来源:
The Golden Rule
黄金准则
NEVER skip TypeScript 6. The only supported paths are 5.x → 6 → 7.Skipping TS 6 produces a wall of hard errors because TS 7 removes everything TS 6 deprecated. Useonly as a temporary pause inside TS 6; it does NOT work in TS 7."ignoreDeprecations": "6.0"
绝对不要跳过TypeScript 6。唯一受支持的迁移路径是 5.x → 6 → 7。跳过TS 6会导致大量严重错误,因为TS 7移除了所有TS 6中标记为弃用的内容。仅可在TS 6中临时使用;该配置在TS 7中无效。"ignoreDeprecations": "6.0"
Quick Triage (1 Minute)
快速诊断(1分钟)
- Detect current version — run (reads
scripts/detect-ts-version.sh).package.json - Classify the path:
- → start with
5.x§ "5.x → 6".references/migration-playbooks.md - → may go directly to TS 7 (see
6.x).references/ts7-go-rewrite.md - wanting TS 7 → must go 5 → 6 → 7 (no shortcuts).
5.x - Intra-version strict-flag rollout (no version change) → see for the optional
references/ts-migrating-tool-guide.mdtool.ts-migrating
- Audit before changing anything — run to detect tooling that breaks under TS 7 (typescript-eslint, ts-morph, ts-node, Vue/Svelte/Astro/MDX/Angular templates, ts-patch, ttypescript, typia,
scripts/audit-ts7-breakers.sh,baseUrl,node10target).ES5
- 检测当前版本 —— 运行(读取
scripts/detect-ts-version.sh)。package.json - 确定迁移路径:
- 当前为→ 从
5.x的「5.x → 6」章节开始。references/migration-playbooks.md - 当前为→ 可直接升级到TS 7(详见
6.x)。references/ts7-go-rewrite.md - 当前为想要升级到TS 7 → 必须按5 → 6 → 7的顺序迁移(无捷径)。
5.x - 同版本内启用严格模式(不升级版本)→ 参考中的可选工具
references/ts-migrating-tool-guide.md。ts-migrating
- 当前为
- 变更前审计 —— 运行检测在TS 7下会失效的工具(typescript-eslint、ts-morph、ts-node、Vue/Svelte/Astro/MDX/Angular模板、ts-patch、ttypescript、typia、
scripts/audit-ts7-breakers.sh、baseUrl、node10目标)。ES5
Project-Type Decision Matrix
项目类型决策矩阵
| Project type | Recommendation | Why |
|---|---|---|
| Greenfield, no API-dependent tooling | Adopt TS 7 directly | Full speedup, no blockers |
| Existing TS project, no special tooling | 5 → 6 → 7 sequentially | TS 6 surfaces every deprecation as a warning first |
| Uses typescript-eslint / ts-morph / API consumers | 5 → 6 → 7 via | TS 7 has no programmatic API until 7.1 |
| Vue / Svelte / Astro / MDX (Volar-based) | Stay on TS 6 | Volar needs the programmatic API; not yet supported |
| Angular with template type-checking | TS 7 for CLI + TS 6 for editor | Microsoft's official split workaround |
| ts-patch / ttypescript / typia / custom AST transformers | Stay on TS 6 until migrated to Oxc/SWC | Transformer API gone in TS 7 |
| 项目类型 | 建议 | 原因 |
|---|---|---|
| 新项目,无依赖API的工具 | 直接采用TS 7 | 完全提速,无阻碍 |
| 现有TS项目,无特殊工具 | 按5 → 6 → 7顺序迁移 | TS 6会先将所有弃用项标记为警告 |
| 使用typescript-eslint / ts-morph / API消费者 | 通过 | TS 7在7.1版本前无编程式API |
| Vue / Svelte / Astro / MDX(基于Volar) | 停留在TS 6 | Volar需要编程式API,暂不支持TS 7 |
| 启用模板类型检查的Angular项目 | CLI使用TS 7 + 编辑器使用TS 6 | 微软官方推荐的拆分解决方案 |
| 使用ts-patch / ttypescript / typia / 自定义AST转换器 | 停留在TS 6,直到迁移到Oxc/SWC | TS 7已移除转换器API |
TS 6 — Top Breaking Changes (Quick View)
TS 6 — 主要破坏性变更(快速概览)
| Change | Old default | TS 6 default | Fix |
|---|---|---|---|
| false | true | Set explicitly or fix errors |
| CommonJS | esnext | Set |
| ES3 | es2025 (floating) | Set explicitly |
| node10 | bundler | Set |
| inferred | | Set |
| all | | Set |
| false | true | Remove |
| false | true | Fix typos or set false for bundler CSS |
| true | false | — |
| varies | true | — |
Deprecated in 6, HARD ERRORS in 7: ; ; ; ; ; ; ; ; ; keyword; on imports; ; + tsconfig present (use ).
target: es5downlevelIterationmoduleResolution: node | node10 | classicmodule: amd | umd | systemjs | nonebaseUrlesModuleInterop: falseallowSyntheticDefaultImports: falsealwaysStrict: falseoutFilemodule Foo {}assert { }/// <reference no-default-lib="true"/>tsc <file>--ignoreConfigFor full detail per change including PR citations, examples, and the official codemod usage, load .
ts5to6references/ts6-breaking-changes.md| 变更内容 | 旧默认值 | TS 6默认值 | 修复方案 |
|---|---|---|---|
| false | true | 显式设置为false或修复错误 |
| CommonJS | esnext | 如需保留则设置为 |
| ES3 | es2025(浮动更新) | 显式设置目标版本 |
| node10 | bundler | Node项目设置为 |
| 自动推断 | | 设置 |
| 所有 | | 设置 |
| false | true | 删除 |
| false | true | 修复拼写错误,或针对打包器CSS设置为false |
| true | false | — |
| 不定 | true | — |
在TS 6中弃用、在TS 7中变为严重错误的配置:;;;;;;;;;关键字;导入时的;;存在tsconfig时使用(改用)。
target: es5downlevelIterationmoduleResolution: node | node10 | classicmodule: amd | umd | systemjs | nonebaseUrlesModuleInterop: falseallowSyntheticDefaultImports: falsealwaysStrict: falseoutFilemodule Foo {}assert { }/// <reference no-default-lib="true"/>tsc <file>--ignoreConfig如需每个变更的详细信息(包括PR引用、示例和官方代码修改工具的用法),请查看。
ts5to6references/ts6-breaking-changes.mdTS 7 — What Changed (Quick View)
TS 7 — 变更内容(快速概览)
- Native Go port; the standard npm package IS TS 7 (
typescript).npm install -D typescript - All TS 6 deprecations become hard errors (see table above).
- No programmatic Compiler API in 7.0 — TS 7.1 will ship a new one. Affects ts-morph, ts-node, ts-jest, ts-loader, ts-patch, ttypescript, typia, typescript-eslint (use the side-by-side pattern below).
- removed — always emits const enums.
preserveConstEnums - now
stableTypeOrderingby default; cannot be turned off.true - NEW flags: (default 4),
--checkers N,--builders N.--singleThreaded - NEW breaking change: template literal types preserve Unicode code points (not UTF-16 code units).
- NEW: JS file handling reworked (Closure-style ,
@enum,@class, postfix?no longer special).! - Performance (official, real OSS codebases): 7.7x–11.9x faster builds (up to 16.7x with ); 6–26% lower memory.
--checkers 8
Full install options, compatibility matrix, performance tables, and known issues in .
references/ts7-go-rewrite.md- 原生Go移植版;标准npm包即为TS 7(执行
typescript安装)。npm install -D typescript - TS 6中所有弃用项在TS 7中变为严重错误(见上表)。
- 7.0版本无编程式Compiler API —— TS 7.1将推出新的API。这会影响ts-morph、ts-node、ts-jest、ts-loader、ts-patch、ttypescript、typia、typescript-eslint(可使用下方的并行安装方案)。
- 移除—— 始终会编译输出const枚举。
preserveConstEnums - 默认设为
stableTypeOrdering;无法关闭。true - 新增命令行参数:(默认4)、
--checkers N、--builders N。--singleThreaded - 新增破坏性变更:模板字面量类型保留Unicode代码点(而非UTF-16代码单元)。
- 新增:JS文件处理逻辑重构(Closure风格的、
@enum、@class、后缀?不再具有特殊含义)。! - 性能表现(官方基于开源代码库的测试):构建速度提升7.7–11.9倍(使用时最高可达16.7倍);内存占用降低6–26%。
--checkers 8
完整的安装选项、兼容性矩阵、性能表格和已知问题请查看。
references/ts7-go-rewrite.mdThe Official Side-by-Side Pattern (TS 7 + TS 6 API)
官方并行安装方案(TS 7 + TS 6 API)
Microsoft's recommended path for projects whose tooling depends on the TS Compiler API. Declare an alias in :
package.jsonjson
{
"devDependencies": {
"@typescript/native": "npm:typescript@^7.0.2",
"typescript": "npm:@typescript/typescript6@^6.0.2"
}
}- runs TS 7 (via the
npx tscalias).@typescript/native - Tools importing (typescript-eslint, ts-morph) transparently get TS 6's API via
typescript.@typescript/typescript6 - A executable is also available if a TS 6 invocation is needed directly.
tsc6 - Remove this workaround once TS 7.1 ships the new API.
对于工具依赖TS Compiler API的项目,微软推荐以下方案。在中声明别名:
package.jsonjson
{
"devDependencies": {
"@typescript/native": "npm:typescript@^7.0.2",
"typescript": "npm:@typescript/typescript6@^6.0.2"
}
}- 将运行TS 7(通过
npx tsc别名)。@typescript/native - 导入的工具(typescript-eslint、ts-morph)将通过
typescript自动使用TS 6的API。@typescript/typescript6 - 同时提供可执行文件,如需直接调用TS 6可使用该命令。
tsc6 - 待TS 7.1推出新API后,即可移除该兼容方案。
The 4-Step Standard Workflow
四步标准迁移流程
- Detect — reports the installed version.
scripts/detect-ts-version.sh - Audit — detects breakers BEFORE any upgrade.
scripts/audit-ts7-breakers.shextracts TS5xxx codes fromscripts/ts6-deprecation-scan.shoutput.tsc - Migrate — follow for the appropriate path. Run
references/migration-playbooks.mdandts5to6 --fixBaseUrlif the user explicitly approves (these are official Microsoft-endorsed codemods). All other changes are manual.ts5to6 --fixRootDir - Verify — diffs diagnostic codes between TS 7
scripts/compare-tsc7-tsc6.shand TS 6tsc. Match on TSxxxx codes, NOT message text (wording differs between compilers). Delete staletsc6files before the first TS 7 run (incompatible between the JS and Go compilers)..tsbuildinfo
- 检测 —— 会报告已安装的TS版本。
scripts/detect-ts-version.sh - 审计 —— 在升级前运行检测可能失效的工具。
scripts/audit-ts7-breakers.sh可从scripts/ts6-deprecation-scan.sh输出中提取TS5xxx错误码。tsc - 迁移 —— 根据对应路径遵循的指引。若用户明确同意,可运行
references/migration-playbooks.md和ts5to6 --fixBaseUrl(这些是微软官方认可的代码修改工具)。其余变更需手动完成。ts5to6 --fixRootDir - 验证 —— 会对比TS 7的
scripts/compare-tsc7-tsc6.sh和TS 6的tsc输出的诊断代码。需匹配TSxxxx代码,而非错误信息文本(不同编译器的措辞可能不同)。首次运行TS 7前,请删除过时的tsc6文件(JS版和Go版编译器的该文件不兼容)。.tsbuildinfo
Critical Rules
关键规则
Always
必须遵守
- ✅ Migrate through TS 6 — never skip it.
- ✅ Match on diagnostic codes (TSxxxx), not message wording.
- ✅ Delete stale before the first TS 7 run.
.tsbuildinfo - ✅ Cite Microsoft's official blog posts as authoritative; treat third-party tutorials as secondary.
- ✅ Run BEFORE any upgrade.
audit-ts7-breakers.sh
- ✅ 必须通过TS 6进行迁移——绝不跳过。
- ✅ 匹配诊断代码(TSxxxx),而非错误信息措辞。
- ✅ 首次运行TS 7前删除过时的文件。
.tsbuildinfo - ✅ 以微软官方博客文章为权威来源;第三方教程仅作为参考。
- ✅ 升级前务必运行。
audit-ts7-breakers.sh
Never
绝对禁止
- ❌ Never install for stable use — it's the legacy nightly package; stable is the standard
@typescript/native-previewpackage.typescript - ❌ Never assert the unverified third-party claims listed in (e.g. "moduleResolution default is node16", "
references/unverified-claims.mdflag exists", "ES5 target is removed in 6", "--ts6-migrationwas removed").--keyofStringsOnly - ❌ Never recommend (the tool) for TS version migration — it only helps tighten compilerOptions within a version.
ts-migrating - ❌ Never assume VS Code needs a setting key to enable TS 7 — install the official extension; it auto-enables.
- ❌ Never auto-edit user source via custom scripts — only detection/audit scripts and officially-blessed codemods ().
ts5to6
- ❌ 绝不要安装用于稳定环境——这是旧版夜间构建包;稳定版为标准的
@typescript/native-preview包。typescript - ❌ 绝不要断言中列出的未经验证的第三方说法(例如"moduleResolution默认值为node16"、"存在
references/unverified-claims.md参数"、"ES5目标在TS 6中已移除"、"--ts6-migration已被移除")。--keyofStringsOnly - ❌ 绝不要推荐使用工具进行TS版本迁移——它仅能帮助在同版本内逐步收紧compilerOptions配置。
ts-migrating - ❌ 绝不要假设VS Code需要额外设置来启用TS 7——安装官方扩展后会自动启用。
- ❌ 绝不要通过自定义脚本自动修改用户源码——仅可使用检测/审计脚本和官方认可的代码修改工具()。
ts5to6
The ts-migrating
Tool — Conditional Offer
ts-migratingts-migrating
工具——使用条件
ts-migratingOffer this tool ONLY when the user wants to enable a stricter (e.g. , , ) on an existing large codebase — NOT for version migration.
compilerOptionnoUncheckedIndexedAccessstricterasableSyntaxOnlyGate conditions (all must hold):
- Existing, non-greenfield TypeScript project.
- The goal is enabling a incrementally.
compilerOption - This is not a tsgo / TS-7 migration.
Warnings:
- The subcommand rewrites source — run on a clean git tree and review the diff.
annotate - The IDE plugin has ZERO effect on ; wire
tscinto CI for it to matter.ts-migrating check - markers are tech debt needing a cleanup sweep.
// @ts-migrating - This is NOT Airbnb's (different tool — JS → TS conversion).
ts-migrate
Full install, commands, and gate logic in .
references/ts-migrating-tool-guide.md仅当用户希望在现有大型代码库中逐步启用更严格的(例如、、)时,才推荐该工具——不可用于版本迁移。
compilerOptionnoUncheckedIndexedAccessstricterasableSyntaxOnly使用条件(需全部满足):
- 现有非新项目的TypeScript项目。
- 目标是逐步启用。
compilerOption - 并非tsgo / TS-7版本迁移。
注意事项:
- 子命令会修改源码——请在干净的git分支上运行并审查差异。
annotate - IDE插件对无任何影响;需将
tsc集成到CI流程中才有效。ts-migrating check - 标记属于技术债务,需后续清理。
// @ts-migrating - 这并非Airbnb的工具(后者用于JS → TS转换)。
ts-migrate
完整的安装、命令和使用条件请查看。
references/ts-migrating-tool-guide.mdCommon Error Codes
常见错误码
| Code | Meaning | Action |
|---|---|---|
| TS5011 | rootDir mismatch | Set |
| TS5101 | Option deprecated, stops in TS {ver} | Add |
| TS5102 | Option removed | Remove from tsconfig |
| TS5107 | Option=value deprecated | Same as TS5101 |
| TS5108 | Option=value removed | Remove |
| TS5111 | Migration info (baseUrl, node10) | See |
| TS5112 | tsc file-args + tsconfig present | Use |
| 代码 | 含义 | 操作 |
|---|---|---|
| TS5011 | rootDir不匹配 | 设置 |
| TS5101 | 选项已弃用,将在TS {ver}版本中移除 | 添加 |
| TS5102 | 选项已移除 | 从tsconfig中删除该选项 |
| TS5107 | 选项=值已弃用 | 同TS5101 |
| TS5108 | 选项=值已移除 | 删除该配置 |
| TS5111 | 迁移信息(baseUrl、node10) | 查看 |
| TS5112 | 传入文件参数并同时存在tsconfig | 使用 |
When to Load References
何时查看参考文档
Load these reference files when the user needs detail beyond the quick-reference above:
| Load This File | When |
|---|---|
| Migrating to TS 6; need full PR-cited detail on each default change, deprecation, or syntax change |
| Adopting TS 7; need install detail, compat matrix, performance tables, known gaps |
| Checking whether a specific tool (typescript-eslint, ts-morph, ts-node, vite, webpack, vitest, etc.) works under TS 7 |
| Need ordered checklists for 5→6, 6→7, or 5→7-via-6 |
| User wants to enable a stricter compilerOption incrementally on an existing large codebase |
| Encountering a claim that contradicts official sources; verify before asserting |
当用户需要超出上述快速概览的详细信息时,可查看以下参考文件:
| 查看该文件 | 场景 |
|---|---|
| 迁移到TS 6;需要每个默认值变更、弃用项或语法变更的详细信息(含PR引用) |
| 采用TS 7;需要安装细节、兼容性矩阵、性能表格和已知问题 |
| 检查特定工具(typescript-eslint、ts-morph、ts-node、vite、webpack、vitest等)是否兼容TS 7 |
| 需要5→6、6→7或5→7(经6中转)的有序检查清单 |
| 用户希望在现有大型代码库中逐步启用更严格的compilerOption |
| 遇到与官方来源矛盾的说法时;需先验证再断言 |
Dependencies
依赖项
- Required for migration: (target version),
typescriptin the project root.tsconfig.json - Optional helpers:
- — official codemod for
@andrewbranch/ts5to6/baseUrl.rootDir - — side-by-side API compat for TS 7.
@typescript/typescript6 - — incremental strict-flag rollout (see guide).
ts-migrating
- 迁移必备:(目标版本)、项目根目录下的
typescript。tsconfig.json - 可选辅助工具:
- —— 用于
@andrewbranch/ts5to6/baseUrl的官方代码修改工具。rootDir - —— 为TS 7提供并行API兼容支持。
@typescript/typescript6 - —— 逐步启用严格模式(详见指南)。
ts-migrating
Package Versions (Verified 2026-07-09)
验证过的包版本(2026-07-09)
json
{
"devDependencies": {
"typescript": "^7.0.2",
"@typescript/typescript6": "^6.0.2"
},
"optionalHelpers": {
"@andrewbranch/ts5to6": "latest",
"ts-migrating": "latest"
}
}All facts in this skill are cited to Microsoft's official TypeScript blog (devblogs.microsoft.com/typescript). Third-party tutorial claims that conflict with official sources are catalogued in and treated as suspect.
references/unverified-claims.mdjson
{
"devDependencies": {
"typescript": "^7.0.2",
"@typescript/typescript6": "^6.0.2"
},
"optionalHelpers": {
"@andrewbranch/ts5to6": "latest",
"ts-migrating": "latest"
}
}本技能中的所有内容均引用自微软官方TypeScript博客(devblogs.microsoft.com/typescript)。与官方来源冲突的第三方教程说法已整理在中,仅供参考。
references/unverified-claims.md