typescript-migration

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TypeScript 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

状态

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. Use
"ignoreDeprecations": "6.0"
only as a temporary pause inside TS 6; it does NOT work in TS 7.
绝对不要跳过TypeScript 6。唯一受支持的迁移路径是 5.x → 6 → 7
跳过TS 6会导致大量严重错误,因为TS 7移除了所有TS 6中标记为弃用的内容。仅可在TS 6中临时使用
"ignoreDeprecations": "6.0"
;该配置在TS 7中无效。

Quick Triage (1 Minute)

快速诊断(1分钟)

  1. Detect current version — run
    scripts/detect-ts-version.sh
    (reads
    package.json
    ).
  2. Classify the path:
    • 5.x
      → start with
      references/migration-playbooks.md
      § "5.x → 6".
    • 6.x
      → may go directly to TS 7 (see
      references/ts7-go-rewrite.md
      ).
    • 5.x
      wanting TS 7 → must go 5 → 6 → 7 (no shortcuts).
    • Intra-version strict-flag rollout (no version change) → see
      references/ts-migrating-tool-guide.md
      for the optional
      ts-migrating
      tool.
  3. Audit before changing anything — run
    scripts/audit-ts7-breakers.sh
    to detect tooling that breaks under TS 7 (typescript-eslint, ts-morph, ts-node, Vue/Svelte/Astro/MDX/Angular templates, ts-patch, ttypescript, typia,
    baseUrl
    ,
    node10
    ,
    ES5
    target).
  1. 检测当前版本 —— 运行
    scripts/detect-ts-version.sh
    (读取
    package.json
    )。
  2. 确定迁移路径:
    • 当前为
      5.x
      → 从
      references/migration-playbooks.md
      的「5.x → 6」章节开始。
    • 当前为
      6.x
      → 可直接升级到TS 7(详见
      references/ts7-go-rewrite.md
      )。
    • 当前为
      5.x
      想要升级到TS 7 → 必须按5 → 6 → 7的顺序迁移(无捷径)。
    • 同版本内启用严格模式(不升级版本)→ 参考
      references/ts-migrating-tool-guide.md
      中的可选工具
      ts-migrating
  3. 变更前审计 —— 运行
    scripts/audit-ts7-breakers.sh
    检测在TS 7下会失效的工具(typescript-eslint、ts-morph、ts-node、Vue/Svelte/Astro/MDX/Angular模板、ts-patch、ttypescript、typia、
    baseUrl
    node10
    ES5
    目标)。

Project-Type Decision Matrix

项目类型决策矩阵

Project typeRecommendationWhy
Greenfield, no API-dependent toolingAdopt TS 7 directlyFull speedup, no blockers
Existing TS project, no special tooling5 → 6 → 7 sequentiallyTS 6 surfaces every deprecation as a warning first
Uses typescript-eslint / ts-morph / API consumers5 → 6 → 7 via
@typescript/typescript6
side-by-side
TS 7 has no programmatic API until 7.1
Vue / Svelte / Astro / MDX (Volar-based)Stay on TS 6Volar needs the programmatic API; not yet supported
Angular with template type-checkingTS 7 for CLI + TS 6 for editorMicrosoft's official split workaround
ts-patch / ttypescript / typia / custom AST transformersStay on TS 6 until migrated to Oxc/SWCTransformer API gone in TS 7
项目类型建议原因
新项目,无依赖API的工具直接采用TS 7完全提速,无阻碍
现有TS项目,无特殊工具按5 → 6 → 7顺序迁移TS 6会先将所有弃用项标记为警告
使用typescript-eslint / ts-morph / API消费者通过
@typescript/typescript6
并行安装,按5 → 6 → 7迁移
TS 7在7.1版本前无编程式API
Vue / Svelte / Astro / MDX(基于Volar)停留在TS 6Volar需要编程式API,暂不支持TS 7
启用模板类型检查的Angular项目CLI使用TS 7 + 编辑器使用TS 6微软官方推荐的拆分解决方案
使用ts-patch / ttypescript / typia / 自定义AST转换器停留在TS 6,直到迁移到Oxc/SWCTS 7已移除转换器API

TS 6 — Top Breaking Changes (Quick View)

TS 6 — 主要破坏性变更(快速概览)

ChangeOld defaultTS 6 defaultFix
strict
falsetrueSet explicitly or fix errors
module
CommonJSesnextSet
commonjs
if needed
target
ES3es2025 (floating)Set explicitly
moduleResolution
node10bundlerSet
nodenext
for Node targets
rootDir
inferred
.
(tsconfig dir)
Set
"rootDir": "./src"
types
all
@types
[]
Set
"types": ["node"]
esModuleInterop
falsetrueRemove
:false
; fix
import * as
import
noUncheckedSideEffectImports
falsetrueFix typos or set false for bundler CSS
libReplacement
truefalse
allowSyntheticDefaultImports
variestrue
Deprecated in 6, HARD ERRORS in 7:
target: es5
;
downlevelIteration
;
moduleResolution: node | node10 | classic
;
module: amd | umd | systemjs | none
;
baseUrl
;
esModuleInterop: false
;
allowSyntheticDefaultImports: false
;
alwaysStrict: false
;
outFile
;
module Foo {}
keyword;
assert { }
on imports;
/// <reference no-default-lib="true"/>
;
tsc <file>
+ tsconfig present (use
--ignoreConfig
).
For full detail per change including PR citations, examples, and the official
ts5to6
codemod usage, load
references/ts6-breaking-changes.md
.
变更内容旧默认值TS 6默认值修复方案
strict
falsetrue显式设置为false或修复错误
module
CommonJSesnext如需保留则设置为
commonjs
target
ES3es2025(浮动更新)显式设置目标版本
moduleResolution
node10bundlerNode项目设置为
nodenext
rootDir
自动推断
.
(tsconfig所在目录)
设置
"rootDir": "./src"
types
所有
@types
[]
设置
"types": ["node"]
等需要的类型包
esModuleInterop
falsetrue删除
:false
配置;将
import * as
改为
import
noUncheckedSideEffectImports
falsetrue修复拼写错误,或针对打包器CSS设置为false
libReplacement
truefalse
allowSyntheticDefaultImports
不定true
在TS 6中弃用、在TS 7中变为严重错误的配置:
target: es5
downlevelIteration
moduleResolution: node | node10 | classic
module: amd | umd | systemjs | none
baseUrl
esModuleInterop: false
allowSyntheticDefaultImports: false
alwaysStrict: false
outFile
module Foo {}
关键字;导入时的
assert { }
/// <reference no-default-lib="true"/>
;存在tsconfig时使用
tsc <file>
(改用
--ignoreConfig
)。
如需每个变更的详细信息(包括PR引用、示例和官方
ts5to6
代码修改工具的用法),请查看
references/ts6-breaking-changes.md

TS 7 — What Changed (Quick View)

TS 7 — 变更内容(快速概览)

  • Native Go port; the standard
    typescript
    npm package IS TS 7 (
    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).
  • preserveConstEnums
    removed — always emits const enums.
  • stableTypeOrdering
    now
    true
    by default; cannot be turned off.
  • NEW flags:
    --checkers N
    (default 4),
    --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
    --checkers 8
    ); 6–26% lower memory.
Full install options, compatibility matrix, performance tables, and known issues in
references/ts7-go-rewrite.md
.
  • 原生Go移植版;标准
    typescript
    npm包即为TS 7(执行
    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(可使用下方的并行安装方案)。
  • 移除
    preserveConstEnums
    —— 始终会编译输出const枚举。
  • stableTypeOrdering
    默认设为
    true
    ;无法关闭。
  • 新增命令行参数:
    --checkers N
    (默认4)、
    --builders N
    --singleThreaded
  • 新增破坏性变更:模板字面量类型保留Unicode代码点(而非UTF-16代码单元)。
  • 新增:JS文件处理逻辑重构(Closure风格的
    @enum
    @class
    ?
    、后缀
    !
    不再具有特殊含义)。
  • 性能表现(官方基于开源代码库的测试):构建速度提升7.7–11.9倍(使用
    --checkers 8
    时最高可达16.7倍);内存占用降低6–26%。
完整的安装选项、兼容性矩阵、性能表格和已知问题请查看
references/ts7-go-rewrite.md

The 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.json
:
json
{
  "devDependencies": {
    "@typescript/native": "npm:typescript@^7.0.2",
    "typescript": "npm:@typescript/typescript6@^6.0.2"
  }
}
  • npx tsc
    runs TS 7 (via the
    @typescript/native
    alias).
  • Tools importing
    typescript
    (typescript-eslint, ts-morph) transparently get TS 6's API via
    @typescript/typescript6
    .
  • A
    tsc6
    executable is also available if a TS 6 invocation is needed directly.
  • Remove this workaround once TS 7.1 ships the new API.
对于工具依赖TS Compiler API的项目,微软推荐以下方案。在
package.json
中声明别名:
json
{
  "devDependencies": {
    "@typescript/native": "npm:typescript@^7.0.2",
    "typescript": "npm:@typescript/typescript6@^6.0.2"
  }
}
  • npx tsc
    将运行TS 7(通过
    @typescript/native
    别名)。
  • 导入
    typescript
    的工具(typescript-eslint、ts-morph)将通过
    @typescript/typescript6
    自动使用TS 6的API。
  • 同时提供
    tsc6
    可执行文件,如需直接调用TS 6可使用该命令。
  • 待TS 7.1推出新API后,即可移除该兼容方案。

The 4-Step Standard Workflow

四步标准迁移流程

  1. Detect
    scripts/detect-ts-version.sh
    reports the installed version.
  2. Audit
    scripts/audit-ts7-breakers.sh
    detects breakers BEFORE any upgrade.
    scripts/ts6-deprecation-scan.sh
    extracts TS5xxx codes from
    tsc
    output.
  3. Migrate — follow
    references/migration-playbooks.md
    for the appropriate path. Run
    ts5to6 --fixBaseUrl
    and
    ts5to6 --fixRootDir
    if the user explicitly approves (these are official Microsoft-endorsed codemods). All other changes are manual.
  4. Verify
    scripts/compare-tsc7-tsc6.sh
    diffs diagnostic codes between TS 7
    tsc
    and TS 6
    tsc6
    . Match on TSxxxx codes, NOT message text (wording differs between compilers). Delete stale
    .tsbuildinfo
    files before the first TS 7 run (incompatible between the JS and Go compilers).
  1. 检测 ——
    scripts/detect-ts-version.sh
    会报告已安装的TS版本。
  2. 审计 —— 在升级前运行
    scripts/audit-ts7-breakers.sh
    检测可能失效的工具。
    scripts/ts6-deprecation-scan.sh
    可从
    tsc
    输出中提取TS5xxx错误码。
  3. 迁移 —— 根据对应路径遵循
    references/migration-playbooks.md
    的指引。若用户明确同意,可运行
    ts5to6 --fixBaseUrl
    ts5to6 --fixRootDir
    (这些是微软官方认可的代码修改工具)。其余变更需手动完成。
  4. 验证 ——
    scripts/compare-tsc7-tsc6.sh
    会对比TS 7的
    tsc
    和TS 6的
    tsc6
    输出的诊断代码。需匹配TSxxxx代码,而非错误信息文本(不同编译器的措辞可能不同)。首次运行TS 7前,请删除过时的
    .tsbuildinfo
    文件(JS版和Go版编译器的该文件不兼容)。

Critical Rules

关键规则

Always

必须遵守

  • ✅ Migrate through TS 6 — never skip it.
  • ✅ Match on diagnostic codes (TSxxxx), not message wording.
  • ✅ Delete stale
    .tsbuildinfo
    before the first TS 7 run.
  • ✅ Cite Microsoft's official blog posts as authoritative; treat third-party tutorials as secondary.
  • ✅ Run
    audit-ts7-breakers.sh
    BEFORE any upgrade.
  • ✅ 必须通过TS 6进行迁移——绝不跳过。
  • ✅ 匹配诊断代码(TSxxxx),而非错误信息措辞。
  • ✅ 首次运行TS 7前删除过时的
    .tsbuildinfo
    文件。
  • ✅ 以微软官方博客文章为权威来源;第三方教程仅作为参考。
  • ✅ 升级前务必运行
    audit-ts7-breakers.sh

Never

绝对禁止

  • ❌ Never install
    @typescript/native-preview
    for stable use — it's the legacy nightly package; stable is the standard
    typescript
    package.
  • ❌ Never assert the unverified third-party claims listed in
    references/unverified-claims.md
    (e.g. "moduleResolution default is node16", "
    --ts6-migration
    flag exists", "ES5 target is removed in 6", "
    --keyofStringsOnly
    was removed").
  • ❌ Never recommend
    ts-migrating
    (the tool) for TS version migration — it only helps tighten compilerOptions within a version.
  • ❌ 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
    包。
  • ❌ 绝不要断言
    references/unverified-claims.md
    中列出的未经验证的第三方说法(例如"moduleResolution默认值为node16"、"存在
    --ts6-migration
    参数"、"ES5目标在TS 6中已移除"、"
    --keyofStringsOnly
    已被移除")。
  • ❌ 绝不要推荐使用
    ts-migrating
    工具进行TS版本迁移——它仅能帮助在同版本内逐步收紧compilerOptions配置。
  • ❌ 绝不要假设VS Code需要额外设置来启用TS 7——安装官方扩展后会自动启用。
  • ❌ 绝不要通过自定义脚本自动修改用户源码——仅可使用检测/审计脚本和官方认可的代码修改工具(
    ts5to6
    )。

The
ts-migrating
Tool — Conditional Offer

ts-migrating
工具——使用条件

Offer this tool ONLY when the user wants to enable a stricter
compilerOption
(e.g.
noUncheckedIndexedAccess
,
strict
,
erasableSyntaxOnly
) on an existing large codebase — NOT for version migration.
Gate conditions (all must hold):
  • Existing, non-greenfield TypeScript project.
  • The goal is enabling a
    compilerOption
    incrementally.
  • This is not a tsgo / TS-7 migration.
Warnings:
  • The
    annotate
    subcommand rewrites source — run on a clean git tree and review the diff.
  • The IDE plugin has ZERO effect on
    tsc
    ; wire
    ts-migrating check
    into CI for it to matter.
  • // @ts-migrating
    markers are tech debt needing a cleanup sweep.
  • This is NOT Airbnb's
    ts-migrate
    (different tool — JS → TS conversion).
Full install, commands, and gate logic in
references/ts-migrating-tool-guide.md
.
仅当用户希望在现有大型代码库中逐步启用更严格的
compilerOption
(例如
noUncheckedIndexedAccess
strict
erasableSyntaxOnly
)时,才推荐该工具——不可用于版本迁移
使用条件(需全部满足):
  • 现有非新项目的TypeScript项目。
  • 目标是逐步启用
    compilerOption
  • 并非tsgo / TS-7版本迁移。
注意事项:
  • annotate
    子命令会修改源码——请在干净的git分支上运行并审查差异。
  • IDE插件对
    tsc
    无任何影响;需将
    ts-migrating check
    集成到CI流程中才有效。
  • // @ts-migrating
    标记属于技术债务,需后续清理。
  • 这并非Airbnb的
    ts-migrate
    工具(后者用于JS → TS转换)。
完整的安装、命令和使用条件请查看
references/ts-migrating-tool-guide.md

Common Error Codes

常见错误码

CodeMeaningAction
TS5011rootDir mismatchSet
"rootDir": "./src"
TS5101Option deprecated, stops in TS {ver}Add
"ignoreDeprecations": "6.0"
(TS 6 only) or fix
TS5102Option removedRemove from tsconfig
TS5107Option=value deprecatedSame as TS5101
TS5108Option=value removedRemove
TS5111Migration info (baseUrl, node10)See
references/ts6-breaking-changes.md
TS5112tsc file-args + tsconfig presentUse
--ignoreConfig
代码含义操作
TS5011rootDir不匹配设置
"rootDir": "./src"
TS5101选项已弃用,将在TS {ver}版本中移除添加
"ignoreDeprecations": "6.0"
(仅适用于TS 6)或修复配置
TS5102选项已移除从tsconfig中删除该选项
TS5107选项=值已弃用同TS5101
TS5108选项=值已移除删除该配置
TS5111迁移信息(baseUrl、node10)查看
references/ts6-breaking-changes.md
TS5112传入文件参数并同时存在tsconfig使用
--ignoreConfig

When to Load References

何时查看参考文档

Load these reference files when the user needs detail beyond the quick-reference above:
Load This FileWhen
references/ts6-breaking-changes.md
Migrating to TS 6; need full PR-cited detail on each default change, deprecation, or syntax change
references/ts7-go-rewrite.md
Adopting TS 7; need install detail, compat matrix, performance tables, known gaps
references/ecosystem-compatibility.md
Checking whether a specific tool (typescript-eslint, ts-morph, ts-node, vite, webpack, vitest, etc.) works under TS 7
references/migration-playbooks.md
Need ordered checklists for 5→6, 6→7, or 5→7-via-6
references/ts-migrating-tool-guide.md
User wants to enable a stricter compilerOption incrementally on an existing large codebase
references/unverified-claims.md
Encountering a claim that contradicts official sources; verify before asserting
当用户需要超出上述快速概览的详细信息时,可查看以下参考文件:
查看该文件场景
references/ts6-breaking-changes.md
迁移到TS 6;需要每个默认值变更、弃用项或语法变更的详细信息(含PR引用)
references/ts7-go-rewrite.md
采用TS 7;需要安装细节、兼容性矩阵、性能表格和已知问题
references/ecosystem-compatibility.md
检查特定工具(typescript-eslint、ts-morph、ts-node、vite、webpack、vitest等)是否兼容TS 7
references/migration-playbooks.md
需要5→6、6→7或5→7(经6中转)的有序检查清单
references/ts-migrating-tool-guide.md
用户希望在现有大型代码库中逐步启用更严格的compilerOption
references/unverified-claims.md
遇到与官方来源矛盾的说法时;需先验证再断言

Dependencies

依赖项

  • Required for migration:
    typescript
    (target version),
    tsconfig.json
    in the project root.
  • Optional helpers:
    • @andrewbranch/ts5to6
      — official codemod for
      baseUrl
      /
      rootDir
      .
    • @typescript/typescript6
      — side-by-side API compat for TS 7.
    • ts-migrating
      — incremental strict-flag rollout (see guide).
  • 迁移必备
    typescript
    (目标版本)、项目根目录下的
    tsconfig.json
  • 可选辅助工具:
    • @andrewbranch/ts5to6
      —— 用于
      baseUrl
      /
      rootDir
      的官方代码修改工具。
    • @typescript/typescript6
      —— 为TS 7提供并行API兼容支持。
    • 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
references/unverified-claims.md
and treated as suspect.
json
{
  "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
中,仅供参考。