tsc-ts:用 TypeScript 编写的 TypeScript
Tsc-ts: TypeScript written in TypeScript

原始链接: https://github.com/vercel-labs/tsc-ts

tsc-ts 是一个实验性的原生 TypeScript 编译器,从 TypeScript-Go (tsgo) 7.0.2 移植并由 scriptc 编译。可通过 npm 安装;它运行平台特定的原生二进制文件。该 monorepo 包含编译器包和参考 tsgo 构建产物,构建/文档需要 Node 24+、Go 1.26 和 clang。该编译器与 tsgo 在约 12,500 个语料文件上进行验证,扫描器、解析器、绑定器、模块解析、配置、诊断、输出、构建/增量和类型检查全部匹配。`tsc-ts --api` 通过 stdin/stdout 为 scriptc 等工具镜像 `tsc --api`,支持部分语言服务方法,但不支持性能分析。它可原生运行或在 Node 下运行。可用命令包括 build、native build、tests、benchmarks、lint 和 format;项目采用 Apache-2.0 许可证。

Hacker News 上一篇帖子介绍了 Vercel Labs 用 TypeScript 编写的 TypeScript 编译器 “tsc-ts”。该帖只有 7 分和 4 条评论。评论者对其用途表示困惑,其中一人认为它可能是为了展示 “scriptc”,并提到声称它比 tsgo 快 2–4 倍;另一人拿“simulation reboot”开玩笑,而其他人不确定什么是梗。还出现了一条 Y Combinator Winter 2027 batch 广告。
相关文章

原文

Vercel Labs Experiment License: Apache-2.0

An experimental TypeScript port of the TypeScript 7.0.2 compiler (TypeScript-Go, or tsgo), compiled to native code with scriptc.

Install the compiler from npm:

npm install -D tsc-ts
npx tsc-ts -p tsconfig.json

The tsc-ts package runs a native executable from a per-platform optional dependency (@tsc-ts/darwin-arm64, @tsc-ts/linux-x64-gnu, …). See packages/tsc-ts.

See CHANGELOG.md for release notes and GitHub Releases for package archives.

To build the packages for the current platform:

npm run pack:npm -w tsc-ts             # packages/tsc-ts/dist/npm/*.tgz
npm run pack:npm -w tsc-ts -- --check  # also install the tarballs and compile a project

-- --binary dist/tsc packs an existing native build, relative to packages/tsc-ts, instead of building one.

Package Description
packages/tsc-ts The compiler, written in TypeScript, with the tsc-ts command line and --api server.
packages/tsgo Reference builds of tsgo (its command line and per-stage drivers) that the tests compare against.

Tasks run with Turborepo.

apps/web contains the tsc-ts compiler guides.

npm run dev:web
npm run build:web
  • Node.js 24+ and npm
  • Go 1.26
  • A scriptc host: macOS, Linux, or Windows, with clang available for linking
npm ci
npm run fetch:upstream   # clone tsgo at the pinned commit
npm run build            # the Node build of tsc-ts (packages/tsc-ts/dist) and the documentation site
npm run build:oracle     # tsgo reference builds in packages/tsgo/dist

package.json pins scriptc 0.3.5, with its @scriptc/threads package. The build fails with any other version.

packages/tsc-ts/src/compiler is the compiler, ported from tsgo 7.0.2 as idiomatic TypeScript. Each part is compared with tsgo on TypeScript's test corpus (about 12,500 files, 17,000 units after splitting multi-file cases):

Part Compared with tsgo Status
Scanner tokens, values, errors, rescans, JSDoc all files match
Parser and AST tree, diagnostics, API source file encoding all units match
Binder symbols, tables, flow graph, name resolution all units match
Module resolution results, package IDs, --traceResolution all requests match
tsconfig.json and programs --showConfig, --listFilesOnly, --explainFiles all cases match
Command line and options output, errors, exit codes, --locale all cases match
Diagnostics catalog messages, 13 translations, output formats all match
JavaScript emit emitted files, 39 option sets all compared units match
Declaration emit .d.ts and .d.ts.map output, declaration errors all units match
--build, --incremental output, .tsbuildinfo, emitted files, --watch all scenarios match
Type checker diagnostics per file all files match

The corpus scripts are in packages/tsc-ts/scripts (*-corpus.mjs).

tsc-ts --api serves the same API as TypeScript 7.0.2's tsc --api, over stdin and stdout, so tools that drive tsc --api (such as scriptc) can run tsc-ts instead.

npm run build -w tsc-ts
node packages/tsc-ts/dist/tsc-ts/src/main.js --api --cwd path/to/project

Native builds read lib files from the executable's directory, or from TSC_TS_LIB_DIR:

npm run build:native -w tsc-ts       # packages/tsc-ts/dist/tsc
npm run build:native:dev -w tsc-ts   # unoptimized, faster to build
TSC_TS_LIB_DIR=upstream/typescript-go/internal/bundled/libs packages/tsc-ts/dist/tsc -p path/to/project

TSC_TS_BIN=packages/tsc-ts/dist/tsc runs the tsc-ts tests that take a native build against it.

The server is checked against tsc --api 7.0.2 response by response, and scriptc builds the same programs with either. It runs on the tsc-ts compiler, natively or under Node.

Language service methods are supported: getCompletionsAtPosition, getJsDocTags, getDocumentationComment, getReferencesToSymbolInFile, getReferencedSymbolsForNode and getSignatureUsages. Like tsc --api, completions that need auto imports (global identifiers, import statements, exhaustive switch cases) report completion list needs auto imports. The profiling methods (startCPUProfile, stopCPUProfile, saveHeapProfile) are not supported.

npm test                     # compare tsc-ts with tsgo
npm run bench -w tsc-ts      # time tsc-ts against tsgo and TypeScript's JavaScript compiler
npm run lint                 # oxlint
npm run format               # oxfmt

Apache-2.0. See THIRD_PARTY_NOTICES.md for TypeScript-Go and other third-party notices.

联系我们 contact @ memedata.com