跪拜 Guibai
← All articles
TypeScript · Rust · Frontend Engineering

Cloudflare's Rust TypeScript Port Matches tsc Error-for-Error, Then Diverges at the Exit Code

By Flynt ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Teams get a real path to in-browser and worker-side TypeScript checking because Rust compiles to Wasm without Go's runtime, which TS7 cannot do. But switching CI to tsrs means revisiting exit-code assumptions and flag compatibility, and Windows-only workflows will have to wait for a later build.

Summary

Cloudflare and VoidZero shipped tsrs, a Rust port of the TypeScript compiler incubated in the Oxc toolchain. The port is not a fork: it translates the Go-based TypeScript 7 compiler function by function, and the compatibility rule is that Go code is the spec. In the official conformance suite, tsrs matches 13,458 of 13,462 error baselines, leaving four edge cases outside normal error scenarios.

On a 199-file project with six planted error categories, tsc 7.0.2 and tsrs 0.18.0 produced ten diagnostics that were character-identical, including four errors cascading from a generic-constraint inference fallback. The one observable difference sat in the process exit code: tsc returned 1, tsrs returned 2, and @tsrs/wasm also returned 2. On a 1-core 2G container, tsrs measured 1.8x to 2.2x faster than tsc, far from the official 8x, because process cold start consumes roughly half the runtime on small projects.

Wasm is where tsrs separates from TS7: @tsrs/wasm runs type checking in browsers and Cloudflare Workers using an in-memory filesystem and JSON diagnostics. The current release is single-threaded, lacks several tsc flags such as --init and --showConfig, ships no Windows or Intel Mac binaries, and tracks the 7.1.0-dev branch, so CI results can drift with upstream commits.

Takeaways
— tsrs is a function-by-function port of the Go-based TypeScript 7 compiler, not a fork, and its compatibility rule is that Go code is the spec.
— On a 199-file project with six planted error categories, tsc and tsrs produced 10 character-identical diagnostics, including cascading errors from a generic-constraint inference fallback.
— The TypeScript conformance suite shows tsrs matching 13,458 of 13,462 error baselines, with 4 mismatches.
— tsc 7.0.2 exits 1 on type errors; tsrs 0.18.0 exits 2, and @tsrs/wasm also exits 2. Exit codes 0-4 are normal compiler states and 5 means a wasm-level crash or out-of-memory.
— On a 1-core 2G container, tsrs was about 1.8x to 2.2x faster than tsc: 70ms vs 125ms at 35 files and 87ms vs 195ms at 199 files, far short of the official 8x because cold start dominates small projects.
— tsrs 0.18.0 ships binaries only for macOS arm64 and Linux x64/arm64; Windows x64 is planned for the next version and Intel Mac is not supported.
— Supported flags are incomplete: --init, --showConfig, and --generateTrace are missing; --locale is ignored; --watch works on Linux and macOS but reports unsupported on Windows.
— The npm latest tag tracks the 7.1.0-dev branch, so installs can drift with upstream dev commits.
— @tsrs/wasm runs on Node 22+ and in browsers, supports an in-memory filesystem, and returns JSON diagnostics with UTF-16 coordinates; first run took about 1075ms with 110MB memory and a second run took about 417ms.
Conclusions

Treating the Go implementation as the spec makes tsrs credible; a port with nicer messages but different error ordering would be useless in CI.

Wasm shifts where type checking can execute, and the Go compiler's runtime cost closes that door for TS7.

Official speedups are measured where type checking dominates; on smaller projects, startup time makes the practical gain closer to 2x.

tsrs and TS7 are actively trading optimizations, so committing to either as the permanent compiler is premature.

Concepts & terms
tsrs
A Rust port of the TypeScript compiler built by Cloudflare and VoidZero, incubated in the Oxc toolchain. It ports the Go implementation of TypeScript 7 function by function and treats Go behavior as the specification for diagnostics, ordering, message text, and exit codes.
TS7
The Go-based native rewrite of the TypeScript compiler from the TypeScript team. It is significantly faster than the original JavaScript compiler and is the reference implementation that tsrs aims to mirror.
compatibility matrix
A nightly report generated by running the official TypeScript test suite against tsrs. It tracks how many diagnostic baselines match the Go implementation; the current score is 13,458 out of 13,462.
@tsrs/wasm
The WebAssembly build of tsrs for browsers and Node 22+. It can check TypeScript projects with an in-memory filesystem and emit JSON diagnostics with UTF-16 coordinates, enabling in-browser type checking.
Oxc
An open-source project building Rust-based JavaScript and TypeScript tooling, including a parser, linter, and compiler infrastructure. tsrs is incubated inside the Oxc toolchain.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗