Cloudflare have created a tool called tsrs. This aims to increase the speed at which we can run type checking on TypeScript by using Rust. It was developped in partnership with VoidZero. Early benchmarks show that they are seeing up to 8x faster type checking speeds. With roughly 70% less memory usage than Typescript 7.0 when using similar worker configurations. As this is an experimental tool you should check for compatibility.
Cloudflare’s tsrs is a Rust based AI assisted Typescript compiler. This has a lot of potential offering increased speed, WebAssembly and potential benefits to large React.js projects. However, this will not automatically increase your website’s runtime speed.
As a developer looking into cloudflare tsrs ai typescript, I think the key thing to ask yourself is how well does this translate into a solid workflow. Having fast type checking can be beneficial as it allows you to verify changes quicker when using a service such as this within modern web development. Especially within larger
What Is Cloudflare’s tsrs, And Why Is It Important?
tsrs is an open source Rust-based reimplementation of the TypeScript compiler, created by Cloudflare, VoidZero and Max Schwenk with the team at TypeScript.
As noted in the official announcement from Cloudflare, tsrs is being developed within the Oxc JavaScript toolchain.
While it may not be a new language, the goal was to keep the existing behaviour of TypeScript but improve how fast it can compile.
It is also based off of Microsoft’s native Go-based TypeScript implementation.
So no changes are made to how developers write their TypeScript.
8 Things Developers Should Know About tsrs:
1. Super Fast Type Checking
Type checking can be dramatically faster with tsrs.
Cloudflare claim it can be up to 8x faster than TypeScript 7.0 in certain benchmarks, using the same number of checkers.
This could help developers saving time with long running type checking for large apps. But I would need to consider how fast it is compared to the most recent compiler.
2. Less Memory Usage
The Rust compiler has the benefit of being more efficient.
Compared to TypeScript 7.0 it has roughly 70% less memory usage according to Cloudflare.
This can help developers with large code bases, monorepos, and those with limited resources in their development environments. This could be really useful for teams who use automated type checking frequently.
3. AI Generated Code Used To Build Compiler
An important part of developing tsrs was the use of AI generated code.
Max Schwenk explained how AI coding assistants were used to help generate the Rust compiler from the TypeScript implementation and conformance tests. His technical report goes into detail about how this was done and the results of performance.
You can see here how AI was used to help develop a complex piece of software, but the generated code would have to be tested, maintained and compatible.
4. Rust Allows WebAssembly
Thanks to Rust we can use tsrs on WebAssembly.
The project includes @tsrs/wasm which allows us to do TypeScript checking on supported browsers and servers.
This could allow us to develop tools within browsers, sandboxed environments and with AI. The main benefit is it can be used on different environments without needing to run a native compiler executable.
5. Compatibility With TypeScript
A faster compiler means nothing if it doesn’t work correctly with existing TypeScript projects. tsrs aims to be very similar to the official TypeScript implementation.
They have lots of conformance tests to compare the output, errors and features between the two compilers. I would recommend looking at the official compatibility docs first.
6. Native TypeScript Compiler (Go) By Microsoft
There already exists a native TypeScript compiler written in Go, commonly known as tsgo by Microsoft.
According to their TypeScript announcement they saw some impressive performance improvements from implementing a native compiler instead of the previous JavaScript one.
tsrs is building upon the improvements made by this project. Both projects are important as any performance improvements found could help improve the wider TypeScript ecosystem.
7. Could Help With React.js Development
Having a faster compiler can really help with development when working with large React applications.
If you have lots of components, shared interfaces and complex type definitions then the checking can take a long time. tsrs could help save time with type checking in React.js Development. However, it won’t directly improve the speed of your React pages or reduce the size of the JavaScript bundle.
8. Experimental Project
Although it has great potential for performance, tsrs is a work in progress. Certain options may not be available in the compiler, editor or platform compared to the reference TypeScript compiler. This can cause issues with the errors returned and exit codes. I would recommend comparing the outputs, looking at what isn’t supported and ensuring it works with your current build tools.
How can you run tsrs in your project?
First, we would recommend running tsrs alongside an existing TypeScript config.
1. Check TS version
Ensure that you are using a compatible version of TypeScript. If you are using an older version of TypeScript then you may need to prepare your project for migration as tsrs uses the TypeScript 7 compiler architecture.
2. Install tsrs
Run the following command in your project:
npm install -D tsrs
3. Run type check
Run type check using the existing TypeScript config:
npx tsrs -p . –noEmit
4. Compare Results
Compare tsrs with the equivalent reference compiler by looking at:
- Time taken for type checking to run.
- Max memory usage.
- Compiler errors.
- Exit codes and will it work with your CI.
We would recommend running tests on the same machine with similar compiler settings and number of workers.
This allows you to test out tsrs.
Should Developers Switch from TypeScript to tsrs?
I would treat tsrs as an experimental optimization rather than an automatic production upgrade.
|
Evaluation factor |
tsrs consideration |
|
Speed |
Promising gains in reported benchmarks |
|
Memory |
Lower usage in selected tests |
|
Compatibility |
Requires project-specific verification |
|
Production adoption |
Best evaluated through controlled testing |
Cloudflare state that TypeScript 7.1 beta has a 2.5x speed increase over TypeScript 7.0, so this shouldn’t be taken as an 8x improvement over all newer compilers.
Benchmark your real project.
Future of tsrs
Cloudflare intends to improve compatibility with tsrs, ensure it keeps up with new updates to typescript and further integration within the Oxc ecosystem.
This shows how developing compilers with AI assistance and using Rust can help to improve software development infrastructure.
Over time I’d expect it to be useful if it can be made compatible, maintainable and deliver real performance improvements.
tsrs looks like it could be useful but in the long run it will depend on it being compatible with TypeScript.
Conclusion
Cloudflare have shown how using Rust, AI assisted development and optimising compilers can help improve development workflows.
It also provides performance improvements which means it’s worth looking into. Especially if you’re working with large TypeScript and React projects.
It also shows how AI assisted software engineering is becoming more prevalent within businesses looking to provide efficient development workflows and AI & Machine Learning development services.
I would recommend keeping an eye on this project, trying it out with your current code bases and implementing it once it has compatibility with your specific project.