Skip to content

chore: upgrade TypeScript to 6.0 - #160

Merged
luojiyin1987 merged 2 commits into
masterfrom
chore/typescript-6
Aug 22, 2026
Merged

chore: upgrade TypeScript to 6.0#160
luojiyin1987 merged 2 commits into
masterfrom
chore/typescript-6

Conversation

@luojiyin1987

@luojiyin1987 luojiyin1987 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Closes #159

改动

package.json

-    "typescript": "^5.9.0"
+    "typescript": "^6.0.3"
-    "ts-jest": "^29.4.0",
+    "ts-jest": "^29.4.7",

tsconfig.json:TS 6 改变了两个 compiler defaults,需要显式固定(零源码修改):

     "esModuleInterop": true,
     "isolatedModules": true,
+    // TS 6 flips the effective noImplicitAny default to true. Pinned to keep
+    // the upgrade diff behavior-preserving; see format-lint-report.ts for the
+    // known implicit-any sites awaiting cleanup.
+    "noImplicitAny": false,
+    // TS 6 no longer infers rootDir (aka.ms/ts6, error TS5011). The JSON
+    // import of ../package.json makes the effective root the project
+    // directory, which preserves the lib/src/** emit layout.
+    "rootDir": "./",

两个默认值变化的处理

1. noImplicitAny 有效默认值翻转为 true

TS 5.9 下 typecheck 通过的代码在 TS 6 报出 6 个隐式 any(集中在 format-lint-report.tstext-table 无类型声明 + 3 个回调参数)。按"升级 PR 不顺手做类型收紧"的原则,显式 "noImplicitAny": false 固定原语义。隐式 any 清理留作独立后续 PR。

2. rootDir 不再自动推断(TS5011,aka.ms/ts6)

tsc -p tsconfig.json 整体编译能推断;但 ts-jest 逐文件编译时推断结果不稳定,25 个 suite 全部失败。显式 "rootDir": "./"——当前有效值就是项目根目录(../package.json 的 JSON 导入把根拉进了编译程序),emit 路径不变。

ts-jest floor 是 TS 6 的必要配套

实测上游 peer contract(npm view):

  • ts-jest 29.4.6"typescript": ">=4.3 <6" — 不支持 TS 6
  • ts-jest 29.4.7"typescript": ">=4.3 <7" — 正式加入 TS 6 支持

原声明 ^29.4.0 会允许 typescript 6.0.3 + ts-jest 29.4.0~29.4.6 这类不属于上游支持范围的组合。CI 全绿只能证明本次解析出的版本能跑,不能证明 floor 正确。因此提到 ^29.4.7——这不是顺手升级,是 TypeScript 6 的 compatibility floor。

版本选择

停在 6.x(^6.0.3),不跟 TS 7.0.2:ts-jest 29.4.12 的 peer contract 是 >=4.3 <7,TS 7 迁移涉及 native compiler 兼容方案,是独立课题。

验证

检查项 结果
npm run typecheck 通过
npm test -- --runInBand 25 suites / 205 tests 通过
npm run build 通过
发布路径 lib/src/lint-md.jslib/src/utils/lint-worker.js 不变,仍为 CJS
npm run test:package 通过(pack → 全局安装 → lint/fix 全链路)

源码 diff:0 文件。

@luojiyin1987

Copy link
Copy Markdown
Contributor Author

commit be13c84: ts-jest floor 提到 ^29.4.7。已用 npm view 实证 peer contract:29.4.6 为 <6,29.4.7 起为 <7。typecheck + 205 tests 复验通过。

@luojiyin1987
luojiyin1987 merged commit e7e5917 into master Aug 22, 2026
7 checks passed
@luojiyin1987
luojiyin1987 deleted the chore/typescript-6 branch August 22, 2026 05:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: upgrade TypeScript to 6.0

1 participant