Skip to content

Upgrade TypeScript 5.9 → 7.0 beta (native Go compiler)#2

Draft
Simply007 wants to merge 3 commits intomainfrom
upgrade/typescript-7-beta
Draft

Upgrade TypeScript 5.9 → 7.0 beta (native Go compiler)#2
Simply007 wants to merge 3 commits intomainfrom
upgrade/typescript-7-beta

Conversation

@Simply007
Copy link
Copy Markdown
Owner

@Simply007 Simply007 commented Apr 23, 2026

Summary

Upgrades the TypeScript compiler from 5.9.3 to 7.0 beta (@typescript/native-preview), which rewrites the compiler in Go and delivers ~8× faster build times. All existing type-level code, type tests, and tooling continue to work without modification to the core arithmetic types.

Also adds a full comparison of the plain-JS calculator vs the type-level calculator, covering both compile-time overhead and runtime parity.

Build-speed comparison

Measured on this project (NodeNext ESM, strict mode, macOS Apple Silicon):

Scenario tsc 5.9.3 tsgo 7.0-dev Speedup
Type-check (--noEmit) ~0.285 s ~0.035 s ~8×
Full build (emit JS + .d.ts) ~0.333 s ~0.043 s ~7.7×

See TYPESCRIPT_7_UPGRADE.md for raw numbers and full change analysis.

JS vs type-level calculator comparison (npm run compare)

Plain JS Type-level
Return type of add(55, 67) number 122 (exact literal)
Build-time cost trivial small (scales with digit count / operand magnitude)
Runtime cost a + b a + bidentical (cast erased at emit)
Recursion limit none Mul first operand ≤ 999

See CALCULATOR_COMPARISON.md for full tables and analysis.

Changes

package.json

  • typescriptnpm:@typescript/native-preview@^7.0.0-dev.20260421.2 (Go-native compiler, tsgo binary)
  • Add typescript-apinpm:typescript@^5.9 alias — kept for dev tools that use the TS programmatic JS API (not yet available in TS 7.0, planned for 7.1)
  • Build script: tsctsgo
  • Add compare script: npx tsx tools/compare-calculator.ts

src/index.ts

  • Remove unused import { SourceMap } from 'node:module'

tools/inspect-types.ts · tools/benchmark-sum.ts · tools/compare-calculator.ts (new)

  • Tool imports updated to typescript-api; new compare tool added

tsconfig.json — no changes needed

Test plan

  • npm run build — compiles cleanly with tsgo
  • npm run test:types — all tsd type assertions pass
  • npm run inspect:sumSum<1234,5678> = 6912
  • npm run benchmark — all Sum cases correct; Mul limit confirmed at 999
  • npm run compare — comparison tool runs end-to-end cleanly

TODO before merging (waiting on stable TS 7.0 release)

  • Replace npm:@typescript/native-preview@^7.0.0-dev.* with typescript@^7.0.0 once published
  • Confirm binary name in stable release (tsgo vs tsc) and update build script
  • Remove typescript-api alias and revert tool imports once TS 7.1 ships stable programmatic API
  • Re-run benchmarks and update TYPESCRIPT_7_UPGRADE.md + CALCULATOR_COMPARISON.md with stable numbers
  • Verify tsd@^0.31.0, tsx@^4.7.0, and @types/node@^25 work with stable TS 7.0
  • Delete the TODO section from TYPESCRIPT_7_UPGRADE.md

Full checklist with context: TYPESCRIPT_7_UPGRADE.md#todo

Known limitation

npm run inspect / npm run benchmark / npm run compare use the TS 5.9 programmatic API (typescript-api alias). TS 7.0 has no stable JS API until 7.1. The TypeScript version: 5.9.3 line in tool output is expected.

- Switch typescript devDep to @typescript/native-preview (tsgo binary)
- Add typescript-api alias (typescript@5.9) for tools that use the programmatic API
- Update build script from tsc → tsgo
- Remove unused `import { SourceMap } from 'node:module'` in src/index.ts
  (TS 7.0 defaults types:[] so @types/node is no longer auto-included)
- Update tools to import from typescript-api instead of typescript
- Add TYPESCRIPT_7_UPGRADE.md with build-speed comparison and change log
- tools/compare-calculator.ts: benchmarks compile-time overhead
  (batched programs to isolate per-type cost) and runtime parity
  (50M iterations, showing as-cast is fully erased)
- CALCULATOR_COMPARISON.md: full comparison with tables and analysis
- package.json: add `npm run compare` script
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.

1 participant