Upgrade TypeScript 5.9 → 7.0 beta (native Go compiler)#2
Draft
Upgrade TypeScript 5.9 → 7.0 beta (native Go compiler)#2
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
tsc5.9.3tsgo7.0-dev--noEmit).d.ts)See
TYPESCRIPT_7_UPGRADE.mdfor raw numbers and full change analysis.JS vs type-level calculator comparison (
npm run compare)add(55, 67)number122(exact literal)a + ba + b— identical (cast erased at emit)Mulfirst operand ≤ 999See
CALCULATOR_COMPARISON.mdfor full tables and analysis.Changes
package.jsontypescript→npm:@typescript/native-preview@^7.0.0-dev.20260421.2(Go-native compiler,tsgobinary)typescript-api→npm:typescript@^5.9alias — kept for dev tools that use the TS programmatic JS API (not yet available in TS 7.0, planned for 7.1)tsc→tsgocomparescript:npx tsx tools/compare-calculator.tssrc/index.tsimport { SourceMap } from 'node:module'tools/inspect-types.ts·tools/benchmark-sum.ts·tools/compare-calculator.ts(new)typescript-api; new compare tool addedtsconfig.json— no changes neededTest plan
npm run build— compiles cleanly withtsgonpm run test:types— alltsdtype assertions passnpm run inspect:sum—Sum<1234,5678> = 6912✓npm run benchmark— allSumcases correct;Mullimit confirmed at 999npm run compare— comparison tool runs end-to-end cleanlyTODO before merging (waiting on stable TS 7.0 release)
npm:@typescript/native-preview@^7.0.0-dev.*withtypescript@^7.0.0once publishedtsgovstsc) and update build scripttypescript-apialias and revert tool imports once TS 7.1 ships stable programmatic APITYPESCRIPT_7_UPGRADE.md+CALCULATOR_COMPARISON.mdwith stable numberstsd@^0.31.0,tsx@^4.7.0, and@types/node@^25work with stable TS 7.0TYPESCRIPT_7_UPGRADE.mdFull checklist with context:
TYPESCRIPT_7_UPGRADE.md#todoKnown limitation
npm run inspect/npm run benchmark/npm run compareuse the TS 5.9 programmatic API (typescript-apialias). TS 7.0 has no stable JS API until 7.1. TheTypeScript version: 5.9.3line in tool output is expected.