Microsoft recently announced its intention to completely overhaul the basis of TypeScript, i.e. the compiler that translates TypeScript into JavaScript and other components that are responsible for interacting with tools and development environments. This move has caught many people off guard, as most people expected that if someone took this step, Rust would be used as the programming language, as there are already popular Rust-based tools in the JavaScript environment, such as the bundler Rspack. However, the TypeScript team with Anders Hejlsberg as lead architect opted for a reimplementation in the Go language instead. The aim of the native implementation in Go, which is compiled – rather than the just-in-time conversion of the TypeScript scripting language into bytecode –, is to improve the execution time of the TypeScript tools and to noticeably reduce memory consumption. According to current benchmarks, the new TypeScript achieves ten times faster build times for various projects.
What is TypeScript?
TypeScript was once born out of necessity to compensate for JavaScript’s greatest weaknesses. For years now, it has been an almost indispensable tool in web development, always slightly ahead of JavaScript in its development at feature level. At its core, TypeScript is a programming language that adds type safety to JavaScript at compile time – with the aim of making it easier to develop larger applications and creating a basis for better development tools. Some of the key benefits of using TypeScript instead of JavaScript include:
- Static typing: TypeScript offers great flexibility on the one hand and helps developers to detect potential errors at an early stage on the other.
- Improved code quality: TypeScript allows a strict definition of interfaces, particularly at the interfaces of modules in an application, but also in libraries, which significantly improves the maintainability and readability of the code.
- Tool support: Numerous tools in the JavaScript ecosystem rely on TypeScript to provide better support for developers, such as development environments like Visual Studio Code.
- Polyfills: TypeScript supports modern features from the ECMAScript standard very early and before most environments integrate the features across the board.
- Structured development: TypeScript introduces further constructs such as interfaces, enums and generics, which allow data structures and interfaces to be better modeled.
- Strict environment: TypeScript uses configuration options such as strictNullChecks to avoid common errors from the outset.
What’s next for TypeScript?
The development team is currently working on version 7, which will be the Go version of the TypeScript compiler, codenamed Corsa. The aim of the native implementation in Go is to improve the execution time of the TypeScript tools and to noticeably reduce memory consumption. The new compiler is expected to be fully-fledged by mid-2025, with support for JavaScript, JSDoc and JSX. The current schedule envisages the following milestones:
- Mid-2025: Fully-fledged version of the command line compiler that can perform type checking and translation of source code.
- End of 2025: Feature-complete version that can build projects.
- End of 2025: Language Service, one of the most important development features.
Why the rewrite is necessary
TypeScript shows its advantages above all in larger applications. However, as the code base grows, TypeScript’s resource requirements for type checking and building also increase. This can lead to opening a project in the development environment taking a long time, as the language service initially processes the code. In addition to the pure runtime, there is another, even greater problem due to the high memory requirements. This can lead to memory problems and, in the worst case, to crashes due to out-of-memory errors. Microsoft is making a surprising choice by opting for a reimplementation in the Go language instead of Rust, which many people expected. The new Go-based compiler is expected to address these performance and memory issues, providing a better development experience for developers.
Sebastian Springer: An expert’s perspective
Sebastian Springer is a JavaScript Engineer at MaibornWolff and a leading expert on JavaScript development. He has a deep understanding of the strengths and weaknesses of TypeScript and has been involved in various projects and initiatives to improve the language. In his opinion, the rewrite of TypeScript in Go is a necessary step towards improving the performance and memory efficiency of the language. As Sebastian says, “TypeScript has been a game-changer for JavaScript development, but its limitations have always been a topic of discussion. The new Go-based compiler is a bold move that will undoubtedly make TypeScript an even more attractive option for developers.”
Conclusion
In conclusion, Microsoft’s decision to rewrite TypeScript in Go is a significant development in the world of web development. The new Go-based compiler is expected to address the performance and memory issues that have plagued TypeScript for years. As the development team works towards a fully-fledged version of the compiler, developers can expect a better development experience and improved performance. The future of TypeScript looks bright, and with the new Go-based compiler, it’s likely to become an even more indispensable tool in web development.