Microsoft sta riscrivendo il compilatore TypeScript in Go

Anders Hejlsberg, chief architect of the TypeScript language, who once created the languages C#, Delphi, and Turbo Pascal, introduced a project for a new compiler for TypeScript — typescript-go (tsgo), developed in the Go language. Like the old compiler, the new project is distributed under the Apache 2.0 license.

The original TypeScript compiler is written in TypeScript and transpiles to JavaScript, which creates scaling issues when used in very large projects. Developers have to deal with significant delays during code loading and checking in integrated development environments, sacrificing development convenience to reduce lag by disabling code checking features in editors. There is also a growing need in the ecosystem for command-line tools that allow for quick code compilation to verify functionality.

It is expected that creating a native compiler and tools for TypeScript will significantly increase build speed, reduce memory consumption, and shorten the launch time of code editors. The high performance of these tools will make the development process in modern code editors more convenient, enable quick verification of the entire project's code, and allow for more advanced refactoring and code analysis techniques, which were previously too costly in terms of resource consumption.

According to TypeScript developers, the new tooling is expected to reduce build time by an order of magnitude. Currently, the new variant of the tsc compiler processes the codebase of the VS Code project in 7.5 seconds, while the old compiler required 77.8 seconds for this operation. In the case of the Playwright codebase, loading times dropped from 11.1 to 1.1 seconds, TypeORM from 17.5 to 1.3 seconds, date-fns from 6.5 to 0.7 seconds, tRPC from 5.5 to 0.6 seconds, and rxjs from 1.1 to 0.1 seconds.

The development of the new compiler has been ongoing since October 2024 by a team of 9 Microsoft employees. At this stage, a working prototype is already available for testing. A preliminary version of the command-line tools with the new implementation of tsc, supporting type checking, is planned to be released by mid-year. The release of the first fully functional version, capable of compiling projects and providing LSP services for development environments, is scheduled for the end of the year.

The TypeScript 6.x branch will continue to be supplied with the old compiler and will include separate changes to prepare for migration to the new implementation. The first release transitioned to the new tooling will be TypeScript 7. For some time, the TypeScript 6.x and 7.x codebases will be supported in parallel and coexist, until the TypeScript 7 branch reaches a mature state ready to fully replace the old tooling.

Before starting work on the project, developers explored the possibility of using various programming languages and experimented with prototypes in different languages. Ultimately, the Go language was chosen for creating the new compiler, as the optimal option for rewriting the codebase of the old compiler. Compared to languages like Rust, Go is closer to TypeScript in semantics and code structure, allowing existing patterns to be preserved during porting. Using Go simplifies the transfer of changes between codebases and reduces the complexity of maintaining old and new versions side by side.

The Go language provides good performance, evolves with a focus on multithreading, and operates efficiently on multi-core systems, with built-in safeguards against memory-related issues. The price of safe memory handling is a garbage collector, which can lead to delays during operation, but for the compiler, such delays are not significant.

Other languages, such as Rust, were also considered, but they conceptualize too differently from TypeScript, and using them would turn the porting process into developing a compiler from scratch, making it difficult to achieve full compatibility with the old compiler, requiring re-solving issues that were already addressed in the old codebase, and would demand significantly more time and resources.

Il linguaggio TypeScript amplia le funzionalità di JavaScript, rimanendo completamente retrocompatibile, il che facilita la migrazione delle applicazioni esistenti a TypeScript. L'applicazione finale in TypeScript viene compilata in JavaScript standard, che può essere eseguito in qualsiasi browser web moderno o utilizzato con piattaforme come Node.js, Bun e Deno. Rispetto a JavaScript, TypeScript si distingue per i meccanismi di definizione esplicita dei tipi, oltre al supporto per l'uso di classi e moduli completi. La tipizzazione statica consente di evitare molti errori durante lo sviluppo, offre opportunità per tecniche di ottimizzazione aggiuntive, semplifica il debugging e rende il codice più leggibile e facilmente modificabile e mantenibile.

Fonte: opennet.ru

Acquista hosting affidabile per siti web con protezione DDoS, VPS VDS server 🔥 Acquista hosting affidabile per siti web con protezione DDoS, VPS VDS server | ProHoster