Skip to main content

Command Palette

Search for a command to run...

I'm porting tsc to Go

Published
3 min readView as Markdown

I’m porting tsc to Go

I’m porting the TypeScript Type Checker tsc to Go, and not Rust. As the creator of SWC, an extensible Rust platform, this might sound strange. Let me explain.

Why port tsc?

As TypeScript continues to rise in adoption, large projects are facing a dilemma: type checking is one of the slowest parts of their workflow. Developers want type safety without the tradeoff of slower iteration cycles.

The TypeScript Compiler, or tsc, checks the validity of your types and compiles your code to JavaScript. The more code you have, the longer it takes to compile. On medium-to-large-sized TypeScript projects, this compilation is extremely slow. While developers can replace the transpilation part of their workflow with SWC, type checking has still been a bottleneck.

What is a type checker?

A type checker validates your program before execution and ensures you've used correct values for function calls and variable assignments. To prevent you from specifying types everywhere, it also infers variable types whenever possible. Type checking helps you develop with confidence, prevent mistakes, and enables smoother refactoring of large codebases.

Why not Rust?

I tried to rewrite tsc in Rust. It started as a side project and was a lot of fun. I started recreating the type checking logic without looking at the tsc source code.

Early tests of my Rust rewrite showed 62x faster type checking than tsc. To measure the compile-time between SWC and tsc, I used the conformance test suite from the official TypeScript compiler. Here were the results (using 8 threads):

  • tsc: 133.2 seconds
  • Rust rewrite: 2.13 seconds (62x faster)

Eventually, I realized that rewriting a massive project such as tsc would be extremely difficult to continue. But the performance gains were exciting. This led me to try another route: porting instead of a complete rewrite. So, I started looking at the TypeScript source code.

tsc uses a lot of shared mutability and many parts depend on garbage collection. Even though I’m an advocate and believer in Rust, it doesn’t feel like the right tool for the job here. Using Rust required me to use unsafe too much for this specific project.

tsc depends on shared mutability and has a cyclical mutable reference. Rust is designed to prevent this behavior. Having two references to the same data (shared mutability) is undefined behavior in Rust.

Your language choice should be determined by the task, and not by preference. So even though I love Rust, I started experimenting with Go and Zig for this project and chose to use Go.

Will it be open-source?

Vercel is sponsoring and funding the work to port tsc to Go. We’re planning to open-source this work in the future. I’ll also be creating a bridge to use this new version of tsc with SWC.

With type checking support, SWC is working to improve the performance of your entire JavaScript / TypeScript toolchain:

  • ✅ Transpilation (replacing Babel)
  • 🚧 Type Checking (replacing tsc)
  • 🚧 Minification (replacing Terser)
  • 🚧 Bundling (replacing webpack)

For project updates, follow me on Twitter.

More from this blog

Labor0를 만든 이유

사람이 병목이 되는 횟수를 줄이기 AI 에이전트 세션을 많이 실행하는 것 자체는 어렵지 않다. 내가 해결하고 싶었던 문제는 세션이 늘어날 때마다 사람이 모든 진행 상황을 확인하고 관리해야 한다는 점이었다. 사람을 병목에서 완전히 빼는 게 목표는 아니다. 사람은 여전히 병목이다. 대신 사람이 개입해야 하는 횟수를 줄이고, 실제로 결정이 필요한 순간에만 사람을

Aug 22, 20265 min read

작업 기록: 자동 QA 구성

최근에 Zephyr Cloud 의 프로젝트에 자동 QA 시스템을 구성했다. 그 작업 기록이다. 원래 이런 작업은 리눅스에서 하는 게 맞다고 생각했다. 그런데 나는 계속 로컬에서 디버깅해야 했고, 개발 흐름상 맥에서 바로 돌릴 수 있어야 했다. 예전에도 자동 QA를 시도한 적은 있었지만 끝까지 제대로 굴러간 적은 없었다. 그러다가 지난주 중반쯤, “이건 로

May 13, 20263 min read

한국의 학벌에 대한 생각

내 블로그의 제목이 kdy1: The way I think 인만큼 앞으로는 내 생각을 더 자주 올리려고 한다. 한국 기준으로, 학벌은 사람을 볼 때 꽤나 유용한 지표이지만, 절대적이지는 않다. 경험적인 얘기일 뿐이지만, 성균관대학교 자퇴생으로서 느낀 것들이 몇 가지 있다. 대학까지 간 사람의 학벌은 학습 능력 x 성실함 에 대체로 비례한다. 그래서 의미가

Apr 3, 20261 min read

kdy1: The way I think

303 posts