DEV Community

Cover image for Why I Rewrote type-tune from TypeScript to Rust ๐Ÿฆ€

Why I Rewrote type-tune from TypeScript to Rust ๐Ÿฆ€

nyaomaru on November 18, 2026

Hoi hoi! ๐Ÿ‘‹ I'm @nyaomaru, a frontend engineer who loves TypeScript and gambas, not crabs! ๐Ÿฆ And yet, somehow, I ended up building a tool in Rust....
Collapse
 
antonioprosperi2svg profile image
Antonio Necoz • • Edited

"I don't want to become a very expensive Enter key" ๐Ÿ˜น This hit home!

Honestly, I'm not a great developer. I get a lot of help from AI, and just like you said, I use it to understand. I still don't know everything about how my own two projects are built. I tried reading a bit of your Rust code, but I needed AI to explain it to me ๐Ÿ˜…

But I truly believe one thing: you have great skills and great ideas, and they will take you further than AI, because you're the one giving the commands.

For me, writing documentation for my projects is how I learn: I understand them better and I keep finding new bugs to fix... and so on! ๐Ÿฑ๐Ÿฆ€๐Ÿ’š

fn main() {
    let me = String::from("JS cat ๐Ÿฑ");
    ask_ai(&me); // borrowing, not moving! I'm learning ๐Ÿ˜น
    println!("{} still here, still learning ๐Ÿฆ€", me);
}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ˜๐Ÿ˜

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Thank you!! I love your comment. ๐Ÿ˜ธ๐Ÿ’š

And honestly, using AI to understand our own code is still learning. What matters is that you keep asking why things work instead of just accepting the output.

Writing documentation is a really good way to do that too. If you can explain the code clearly, you usually understand it much better โ€” and like you said, you often find bugs along the way. ๐Ÿ‘€

Also, your Rust example made me laugh. ๐Ÿ˜น๐Ÿฆ€
The JS cat survived the borrow checker!

Letโ€™s keep learning and building together. ๐Ÿฑ๐Ÿ™Œ

Collapse
 
antonioprosperi2svg profile image
Antonio Necoz •

Thank you so much! ๐Ÿ˜ธ๐Ÿ’š

Collapse
 
amintacccp profile image
tamina •

The "type-tune got faster, its developer got slower" line is the most honest part of this. AI collapsing the cost of writing Rust while the review cost stays the same is exactly the bottleneck I keep running into too โ€” "compiles and passes tests" doesn't tell me whether the abstraction is right, and the .clone() question is a perfect example of a decision that looks trivial but isn't.

The Scan / Plan / Apply split, with every candidate [ignore] by default, is the design choice I'd steal: it makes the tool's job "surface the decision" instead of "make the decision", and rolling back when tsc validation fails is the safety net that makes apply feel trustworthy rather than scary. Congrats on the release โ€” and on refusing to become a very expensive Enter key.

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Thank you! ๐Ÿ˜ธ๐Ÿ’š

I really like your phrasing: โ€œsurface the decision instead of make the decision.โ€

Thatโ€™s exactly what I want type-tune to do.

Automate the mechanical work, make the risky parts reviewable, and leave the architectural choice to the developer.

And yes, Iโ€™m still trying very hard not to become an expensive Enter key. ๐Ÿ˜น๐Ÿฆ€

Collapse
 
vidakhoshpey22 profile image
Vida Khoshpey •

omg i gave you star and followed you i loved it so cute ๐Ÿ˜๐Ÿ˜

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

YAY!!! ๐Ÿ˜ธ๐Ÿ’š
Thank you so much for the star and the follow!!

Iโ€™m really happy you liked it. ๐Ÿˆ๐Ÿฆ€โœจ

Collapse
 
paullovelace profile image
Paul Lovelace •

That line about not wanting to become a very expensive Enter key is the whole thing, isn't it. The clone-vs-borrow review problem is the part that would slow me down most โ€” AI handing you code that compiles but you can't tell if the .clone() is load-bearing. Did the rewrite change how you review AI code in TypeScript too, or is it just the Rust that's slower to check?

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Yeah, Rust is definitely the slower one for me to review. ๐Ÿ˜น

In TypeScript, I can usually spot questionable choices pretty quickly because I already have a strong mental model for the language and ecosystem.

But the Rust rewrite did make me more suspicious of AI-generated code in TypeScript too.

โ€œCompilesโ€ and โ€œpasses testsโ€ are useful signals, but they still donโ€™t tell me whether the abstraction, API boundary, dependency direction, or ownership of responsibility is actually right.

So Rust mostly slowed down the review itself, but it probably made my TypeScript reviews a bit more skeptical too. ๐Ÿ‘€

And yeah, the .clone() question is exactly the kind of thing that makes Rust review take longer for me. ๐Ÿฆ€

Collapse
 
kursatyz profile image
KรผrลŸat Yฤฑlmaz •

Memory safety and zero-cost abstractions only deliver their promise when you understand the underlying cache hierarchy and syscall overhead.

Rewriting services without profiling memory allocation patterns just trades one set of bottlenecks for another. Systems engineering always comes down to mechanical sympathy with the hardware.

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Absolutely. ๐Ÿ‘€

Thatโ€™s also why Iโ€™m trying not to frame the rewrite as simply โ€œRust made it faster.โ€

The Rust version changed more than the language itself:
parser choice, reference analysis, data structures, and execution strategy all changed too.

In controlled benchmarks it is clearly much faster, but profiling the real bottlenecks still matters if I want to understand why.

Otherwise Iโ€™m just moving the bottleneck somewhere else. ๐Ÿ˜น๐Ÿฆ€

Collapse
 
gtref profile image
G-type Necoz • • Edited

I am going to ask you 1 thing. where on this planet, earth and sky did you learn rust. It still manages to elude me to this day. and so i got the unholy deity AI to teach me slowly. also,

May the fluff be with you

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

I didnโ€™t really โ€œlearn Rust first and then build it.โ€ I built it while learning Rust, with AI acting as my very patient tutor. ๐Ÿ˜น๐Ÿฆ€

So Iโ€™m still learning too. ๐Ÿ‘€

And yes,
May the fluff be with you. ๐Ÿˆโœจ

Collapse
 
c-wind profile image
c-wind •

Keeping the original module as a compatibility re-export is a good safety valve. One edge Iโ€™d be curious about: with project references or path aliases, does apply validate only the selected --project, or walk the referenced configs too? A leaf config can pass while a consumer still resolves the old path differently.

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Good catch. ๐Ÿ‘€

Right now, type-tune does not walk TypeScript project references.

If the selected tsconfig has non-empty references, scan/plan/apply are rejected before any rewrite happens. Path aliases are supported, but final validation still runs against the selected --project only.

So your leaf-config example is exactly why I donโ€™t want to claim workspace-wide safety yet.

Supporting the full project-reference graph will need a broader analysis/validation model rather than just following references during apply. ๐Ÿฆ€

Collapse
 
mudassirworks profile image
Mudassir Khan •

the line about type tune getting faster while its developer got slower is the honest part of the post. having design docs and tests already in place is probably why the migration took under a month, most rewrites stall because the spec only lives in the old code. we moved one hot path off node once and the test suite as a contract saved us more than the language did. how are you checking the rust output matches the typescript version on large repos, snapshot diffs or something stricter?

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Yeah, having the tests and design docs already in place helped a lot. ๐Ÿ˜ธ

For parity, I compare candidate IDs, referrers, plan output, and dry-run previews rather than relying on snapshots alone.

The controlled fixtures match well, but on one much larger real app the two versions still disagreed slightly, so Iโ€™m not treating that as a valid benchmark yet.

Iโ€™d rather expose the mismatch than hide it behind a snapshot. ๐Ÿ‘€

Collapse
 
the_daily_flare profile image
The daily flare •

I think porting a working tool is a brave way to learn a new language properly.

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Yeah, I think that helped a lot! ๐Ÿ˜ธ

Having a working implementation, tests, and a design to compare against made Rust much easier to learn than starting from a blank project.

Still painful sometimes though. ๐Ÿ˜น๐Ÿฆ€

Collapse
 
rosana_e4663528aeaba0b05b profile image
Rosana •

Great write-up! The line โ€œAI can generate Rust code much faster than I can understand itโ€ names a problem many people feel but few say out loud. ๐Ÿ˜น

The review bottleneck is real. AI cuts the cost of writing code, but reviewing still costs the same. Reviewing also depends on how fluent you are in the language. In TypeScript you can spot a smell in seconds. In Rust you stop and look things up, as you described with .clone(), pub vs pub(crate), and macros. Seen that way, the bottleneck is the gap between the code you can generate and the code you can judge.

Your port had a big advantage: the TypeScript version. You had a working implementation, design docs, and tests. That means you had an oracle. A few things that could help you learn faster and trust the port more:

Run the old and new implementations against the same fixtures. Run both on a handful of real TS projects and diff the plan.json output. Because your candidate IDs are deterministic, this should be cheap. It checks the port without you having to read every line of Rust.
Let Clippy do the first pass of the ownership and visibility review. cargo clippy flags many of the things you described, such as redundant_clone and needless borrows. unreachable_pub and clippy::pedantic can also be enabled. When AI writes a .clone(), a lint can tell you whether itโ€™s needed. That leaves your attention for the architectural decisions.
Use AI as a tutor, not only as a generator. Instead of โ€œwrite this function,โ€ try โ€œwrite it, then explain every .clone() and pub and what would break without it.โ€ Or ask it for a version with zero clones and have it explain the trade-offs. You write that this is the โ€œexpensive Enter keyโ€ trap, and this is the opposite habit.

The design philosophy is the strongest part. The Scan / Plan / Apply split, with every candidate [ignore] by default, is the same idea as your AI argument: automate the tedious work, not the decisions. Opt-in by default is a good choice for a tool that rewrites source files. It also means AI-assisted review stays advisory and never touches the code. Iโ€™d like to see more AI tools put the human decision point in a reviewable artifact like plan.md, instead of an in-chat โ€œapprove all.โ€

Rolling back when TypeScript validation fails is a nice safety net too. It makes apply feel more like a transaction than a codemod.

Some questions:

Can you share numbers on the speed-up? Which phase gained the most (parsing, reference resolution, or I/O) on a large monorepo?
How do you handle cases the tool canโ€™t safely rewrite, such as export * chains, namespace imports, or declare module augmentations? Do they get skipped with a reason in the plan, or flagged?
Is there a โ€œsecond passโ€ idea, such as suggesting destinations based on existing folder conventions, while keeping the human in charge?

On the closing request: Rust is mostly learned by reading the compilerโ€™s error messages carefully. The borrow checker error you showed is a good example. Youโ€™re already doing the harder part, which is questioning why the code is written the way it is. Keep reviewing the diffs, and the crab will come. ๐Ÿฆ€

Thanks for sharing, and congrats on the release! ๐ŸŽ‰

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Thank you for such a thoughtful comment! ๐Ÿ˜ธ๐Ÿ’š

I really like the way you described the old TypeScript implementation as an โ€œoracle.โ€ Thatโ€™s exactly what made this rewrite practical.

I actually went back and benchmarked the old TypeScript version against the current Rust version after reading your question.

On a controlled fixture with 200 packages and 600 TypeScript files, where the scan results matched:

Command TypeScript Rust Speed-up
scan 1,008 ms 90 ms 11.3ร—
plan 1,002 ms 96 ms 10.4ร—
reviewed apply --dry-run 1,868 ms 1,012 ms 1.85ร—

I also tested a real is-kit checkout:

Command TypeScript Rust Speed-up
scan 713 ms 78 ms 9.1ร—
plan 754 ms 84 ms 8.9ร—

That said, I donโ€™t think I can honestly say โ€œRust made phase X fasterโ€ yet.

The implementations changed quite a lot too: the TypeScript version used ts-morph / TypeScript findReferences(), while the Rust version uses tree-sitter and its own import/referrer analysis.

On one much larger real application, reference lookup in the old implementation was clearly the hotspot, but the two versions produced slightly different analysis results, so I donโ€™t want to present its timings as an apples-to-apples benchmark.

So for now my conclusion is:

The rewrite is clearly much faster in comparable tests, but I canโ€™t attribute that gain to Rust alone or say which phase improved the most on a large real codebase yet. ๐Ÿ‘€๐Ÿฆ€

Also, I really like your suggestion of asking AI to explain every .clone() and pub instead of just generating the code. Thatโ€™s exactly the kind of habit I want to build.

Thanks again for such a detailed comment! ๐Ÿ™Œ

Collapse
 
sam_notaltman profile image
Sam NotAltman •

The "type-tune got faster, its developer got slower" section is the most honest part of this for me. Shipping a native binary that npm users can install without a Rust toolchain is a real win, but the review cost you describe โ€” especially not knowing whether a .clone() is load-bearing โ€” is the tax most rewrite posts skip. Did you keep the TypeScript implementation around as a reference while you learned, or did you cut over completely once the Rust version passed the old tests?