TypeScript Is Being Rewritten In Go |
Written by Mike James |
Wednesday, 19 March 2025 |
The TypeScript team at Microsoft has released details of ongoing work they've begun on - a native port of the TypeScript compiler and tools with Go as the language of choice for the project. TypeScript is a superset of JavaScript that adds optional static types which can be checked by the TypeScript compiler to catch common errors in your programs. TypeScript can use this information to help you avoid about mistakes like typos, missing arguments, or forgetting to check for null and undefined. Anders Hejlsberg, lead architect of TypeScript, gave details of the work in a blog post and a YouTube video in which he said that the current use of TypeScript as the language in which TypeScript is implemented has limitations, particularly for performance and scalability. "The JavaScript runtime platform is really optimized for UI and browser usage, and not so much for compute intensive workloads like compilers and system level tools." He says that customers report they run out of memory as their codebases grow, and that the TypeScript team feels they've: "likely reached the limit of what we can squeeze out of JavaScript".. Hejlsberg says the native implementation will drastically improve editor startup, reduce most build times by 10x, and substantially reduce memory usage: "By porting the current codebase, we expect to be able to preview a native implementation of tsc capable of command-line typechecking by mid-2025, with a feature-complete solution for project builds and a language service by the end of the year. " Hejlsberg says that as most developer time is spent in editors, it is where performance is most important, and the new native implementation should be able to provide fast editor experiences. Using the Visual Studio Code codebase as a benchmark, the current time to load the entire project in the editor on a fast computer is about 9.6 seconds. This drops down to about 1.2 seconds with the native language service, an 8x improvement in project load time in editor scenarios. Overall memory usage also appears to be roughly half of the current implementation, though the team hasn't actively investigated optimizing this yet and expect to realize further improvements. In an FAQ on the choice of Go as the language for the rework,Ryan Cavanaugh, Development lead for the TypeScript team at Microsoft, said the team extensively evaluated many language options, and also considered hybrid approaches where certain components could be written in a native language, while keeping core typechecking algorithms in JavaScript. He said the team wrote multiple prototypes experimenting with different data representations in different languages, and did deep investigations into the approaches used by existing native TypeScript parsers like swc, oxc, and esbuild. Go did the best when considering multiple criteria, of which the most important is the need to keep the new codebase as compatible as possible, both in terms of semantics and in terms of code structure. The developers expect to maintain both codebases for some time, and other languages that require fundamental rethinking of memory management, mutation, data structuring, polymorphism, laziness, etc., might be a better fit for a ground-up rewrite, but the work is being undertaken as a port that maintains the existing behavior and critical optimizations built into the language. Idiomatic Go strongly resembles the existing coding patterns of the TypeScript codebase, which makes this porting effort much more tractable. Acknowledging some weak spots, Go's in-proc JS interop story is not as good as some of its alternatives, and the developers have plans to mitigate this. The Go version will first appear as TypeScript 7. The most recent TypeScript release was TypeScript 5.8, with TypeScript 5.9 coming soon. The JS-based codebase will continue development into the 6.x series, and TypeScript 6.0 will introduce some deprecations and breaking changes to align with the upcoming native codebase. You might think that the idea of using a compiler implemented in native code by compiling Go, for a language, TypeScript, that "compiles" to JavaScript, a language that is interpreted, all thought up by the father of C# and inventor of the common language runtime, is about as strange as it gets.
More InformationRelated ArticlesTypeScript - Microsoft's Replacement For JavaScript To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info |
Last Updated ( Wednesday, 19 March 2025 ) |