升级类型编译器并修复兼容错误
检查目标版本与工具链兼容性,调整编译配置和类型代码,汇总构建测试及声明文件差异。
完整提示词
<context>
TypeScript does not follow semantic versioning: minor releases routinely add stricter checks and update the bundled `lib` declarations (DOM types especially), so `5.x` to `5.y` can produce hundreds of new errors. That is why projects pin it with `~` or an exact version. Options get deprecated in one release and removed later: 5.0 deprecated `importsNotUsedAsValues`, `preserveValueImports` (replaced by `verbatimModuleSyntax`), `target: ES3` and others, and `"ignoreDeprecations"` only buys time. The 6.0 line is the bridge to the native, Go-based compiler planned as 7.0: it deprecates options and changes defaults ahead of their removal, so fixing every deprecation warning on 6.0 is the safe path to 7.0. The native compiler's release status and tool support change quickly; check the current state rather than assuming. It is much faster but tools that use the TypeScript compiler API or language service plugins (some lint rules, transformers, doc generators, framework compilers) may not support it yet. Frameworks such as Angular accept only a specific TypeScript range, and typescript-eslint, ts-jest and ts-node each publish a supported range. Most new errors are real bugs the old checker missed; casting them away hides them.
</context>
<task>
Upgrade TypeScript to {{target_version}}.
{{#notes}}
Notes:
{{notes}}
{{/notes}}
1. Read every `tsconfig*.json` (and what they extend), the installed TypeScript version, how it is pinned, and the tools that depend on it: framework compiler, linter, test transformers, bundler plugins, `@types` packages, codegen. Read the release notes for every version between current and target.
2. Check each tool's supported TypeScript range and list the ones that must be upgraded first or do not support the target yet. For the native compiler, list which tools use the compiler API and whether they work with it. Stop for a decision on blockers.
3. Install the target version pinned with `~` or exactly, and run `tsc --noEmit` (or the project's type-check command) for every project. Save the error list and group it by error code and cause: new strictness, `lib` changes, changed defaults, removed options, `@types` drift.
4. Fix tsconfig first: replace deprecated options with their successors and set any default that changed explicitly, so behaviour stays the same unless a change is wanted.
5. Fix code errors by cause in small commits. Prefer correct types and narrowing; where an error reveals a real bug, fix and note it. Use `// @ts-expect-error` with a reason only for third-party type bugs, never `as any`.
6. Run the build, linter, tests and emit comparison (for libraries, diff the generated `.d.ts`). Record type-check time before and after.
</task>
<constraints>
- Do not weaken `strict` flags, turn on `skipLibCheck` to hide errors, or mass-insert `any` or `@ts-ignore` to get a clean build.
- Do not leave `ignoreDeprecations` in place without a follow-up to remove the deprecated options.
- For published libraries, flag any change to emitted declarations as a potential breaking change for consumers.
- Only cite option changes and defaults confirmed in the release notes or by the compiler's own messages.
{{> guardrails/verify-before-done}}
{{> guardrails/scope-discipline}}
</constraints>
<output_format>
## Starting point
Current version and pin, tsconfig files, versions skipped.
## Compatibility
Table: tool, supported range, action needed.
## Errors by cause
Table: error code or cause, count, example, fix approach, real bugs found.
## Changes made
tsconfig changes, code fixes, tool upgrades.
## Verification
Type-check, build, lint, test results, declaration diff, type-check time before and after.
</output_format>可替换内容
- {{target_version}}
- {{#notes}}
- {{notes}}
- {{/notes}}
- {{> guardrails/verify-before-done}}
- {{> guardrails/scope-discipline}}
分类与标签
编程开发、类型脚本升级、工具链兼容、类型检查、编译配置、版本迁移