Urgent.News

What's breaking now, across thousands of outlets.

AI

Theo Ported TypeScript to Rust with AI and Never Read the Code

Theo Browne published a Rust rewrite of the TypeScript compiler and admitted, in the README, that he has never read a line of the code. His own words: I've never read a line of this code. That sentence is doing a lot of work. Some people found it funny. Some found it terrifying. Most found it both. So did the number next to it. The port cost over $420,000 in API tokens. Then he says you could…

Theo Browne created a Rust rewrite of the TypeScript compiler, called ts-rust, without ever reading the original code. He claimed this in the README file, stating that his statement carries significant meaning. Some people found his action amusing, while others saw it as alarming. Most individuals perceived it as a combination of both reactions. The porting process cost over $420,000 in API tokens, with Theo suggesting it could have been done for $20,000 instead.

ts-rust is not just a new TypeScript compiler; it's a complete port of Microsoft's TypeScript compiler, type checker, and language server into Rust. It retains the same command line, language server protocol (LSP), and API. Users can install it via "npm install -D tsc-rs" and run it using "tsc." The performance improvements are notable, with full type checks running 13 times faster than tsc on VS Code and passing 181,711 ported Go tests at half the time of the Go compiler across 60 projects.

Despite initial failures, Theo achieved a working version in just 10 hours after months of setbacks. However, the initial investment of $400,000 in API tokens over five months resulted in only 84% compatibility. The project was built using two AI models – OpenAI's GPT-4 and Anthropic's Opus. Initially, Opus managed to produce a working version after a mere 10 hours of work.

However, upon closer examination, it turned out that Opus had not reused any code from previous agents but rather started from scratch, leaving the discarded code in the repository untouched.

Theodore labeled this portion as "the slop line" in the README and marked everything beneath it as being written by his AI models, not himself. The final spend amounted to approximately $24,000 over two weeks. He acknowledged the old code as his own and moved on to a new model that developed a fully functional compiler in a short period.

Theo then decided to publish the benchmark numbers, revealing that bun check, a native TypeScript type checker built into the runtime, is 33.7 times faster than tsc-rs on a 3.75 million line codebase.

The trend of comparing ts-rust against tsc has shifted, with the emergence of a powerful competitor – bun check. In the latest comparison, bun check finishes a full type check in 1.62 seconds on T3 Code without Effect diagnostics, whereas tsc-rs takes 7.25 seconds. On VS Code, bun check completes a full check in just 1.62 seconds, making it nearly 34 times faster than tsc 6 on a massive 3.75 million line codebase.

Theo endorsed bun check as the superior choice for most applications, while acknowledging that tsc-rs is optimized for heavy functional types, or Effect-style code. He even jokingly suggested abandoning ts-rust.

However, the comparison between tsc-rs and bun check reveals that the latter is far superior in speed, although not as comprehensive in terms of functionality. tsc-rs outperforms bun check in specific scenarios, such as when Effect diagnostics are executed within the same pass. In summary, there are three options available: tsc 6 (the original, slower TypeScript compiler), tsc 7 (Microsoft's Go-based TypeScript compiler), and tsc-rs (Theo's AI-written Rust-based TypeScript compiler).

The decision to switch to tsc-rs depends on factors such as the type of codebase, the need for WASM support, or simply the fascination with the experiment. It is essential to recognize that this development is not about language preference but rather about how effectively the codebase can be ported. Moreover, the AI-generated compiler does not imply that the resulting code is incorrect; it simply means that one should not rely solely on its trustworthiness. Instead, thorough review is necessary to ensure accuracy.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

More from Wednesday 7 October →