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. ๐๐ฆ
Recently, I released a new open-source CLI tool called type-tune.
type-tune
Give shared TypeScript types a better home. ๐ธ
Scan. Review. Move. Validate.
type-tune is a Rust-powered CLI that finds shared TypeScript type aliases and interface declarations and helps move them without manually chasing imports.
It creates a reviewable plan, updates supported type imports and re-exports, and validates the rewrite with TypeScript. You decide what moves and where.
Guides for installation, the first scan, and the review workflow live in the official documentation. Releases are listed on GitHub Releases, and the package is type-tune on npm.
Why type-tune?
Types often start next to a component or utility, then end up shared across a project. Moving them later means tracking imports, local dependencies, and barrels by hand.
- Discover shared types with deterministic candidate IDs.
-
Review
plan.mdand choose the destination before making changes. - Rewrite supported type-only imports, aliases, and simple barrels while keeping compatibility re-exports at the originalโฆ
type-tune finds shared TypeScript types and helps move them to a better place without manually updating imports, dependencies, and barrel exports.
But why is a TypeScript tool created by a TypeScript lover written in Rust? ๐ค
๐ It All Started with TypeScript
Naturally, the original implementation of type-tune was written in TypeScript.
It was already complete by September, with nearly 20,000 lines of TypeScript, including tests, comments, and blank lines.
Around that time, I happened to watch this video by DHH.
I didn't agree with everything, but I particularly liked the idea of taking advantage of this era to pursue things that genuinely excite us.
Of course, outside of personal projects, I don't think we can simply hand everything over to AI. Someone still needs to understand and maintain the software.
But while watching the video, a simple thought crossed my mind.
If it's possible to go from Rails to Rust, why not TypeScript to Rust? ๐ฆ
๐ฆ From TypeScript to Rust
I already had a working implementation, design documents, tests, and well-defined TypeScript types.
For example, translating a data model like this:
type CandidateKind = "typeAlias" | "interface";
type Candidate = {
id: string;
name: string;
kind: CandidateKind;
referrers: string[];
};
Into something like this:
enum CandidateKind {
TypeAlias,
Interface,
}
struct Candidate {
id: String,
name: String,
kind: CandidateKind,
referrers: Vec<String>,
}
Of course, migrating the entire application involved much more than translating type definitions.
But having an existing design and implementation made it much easier.
With the help of AI, I completed the migration in less than a month while working on it as a side project.
The results were satisfying ๐ป
- Better execution performance.
- Native binary distribution.
- No Rust development environment required for npm users.
You can still install type-tune like any other familiar TypeScript development tool.
pnpm add -D type-tune
The npm launcher requires Node.js 22+, but the core implementation runs as a native binary.
So far, so good!
Except for one little problem. ๐ฟ
๐ type-tune Got Faster. Its Developer Got Slower.
I barely knew Rust. ๐น
I'm comfortable reviewing AI-generated TypeScript code, but with Rust, I'm still learning the fundamentals.
For example, consider ownership and borrowing.
In TypeScript, this is perfectly fine:
function printName(name: string) {
console.log(name);
}
const name = "OrderSummary";
printName(name);
console.log(name); // OK
However, a similar implementation in Rust doesn't compile.
fn print_name(name: String) {
println!("{}", name);
}
fn main() {
let name = String::from("OrderSummary");
print_name(name);
println!("{}", name); // Error: value borrowed after move
}
The ownership of name is transferred to print_name.
One way to fix this is to borrow the value instead.
fn print_name(name: &str) {
println!("{}", name);
}
fn main() {
let name = String::from("OrderSummary");
print_name(&name);
println!("{}", name); // OK
}
Another option is to clone the value.
print_name(name.clone());
println!("{}", name); // OK
Both solutions compile, but cloning unnecessarily can introduce additional allocations.
So when AI generates a .clone(), I need to understand whether it's actually necessary or whether borrowing would be more appropriate.
The same applies to visibility boundaries.
For example, making an internal helper public might solve an accessibility issue:
pub fn resolve_destination() {
// ...
}
But if the function is only used within the same crate, exposing it publicly may be unnecessary.
pub(crate) fn resolve_destination() {
// ...
}
And if it's only used within its own module, it can remain private.
fn resolve_destination() {
// ...
}
The compiler accepts all three declarations, but each represents a different architectural decision.
I'm also still learning when macros are appropriate and when ordinary functions are sufficient.
AI can generate code that compiles, but I still need to understand whether its design choices are appropriate.
In TypeScript, I can make these decisions relatively quickly. In Rust, I often need to stop and learn something before continuing my review.
AI can generate Rust code much faster than I can understand it.
I wanted to accelerate the development of my side project, but I introduced a new bottleneck.
Myself.
What a wonderful optimization! ๐น
๐จ Creating Without Learning
Of course, I could just vibe code.
I could keep pressing Enter whenever AI asks for approval and probably release features faster.
But for me, creating something without learning anything is just another task.
And I believe that if I keep doing nothing but those tasks, I'll gradually lose my ability to create.
I enjoy using AI to learn unfamiliar concepts and explore new approaches.
But I don't want to spend my time simply producing things without understanding them.
I don't want to become a very expensive Enter key. ๐น
Do I regret choosing Rust?
Not at all!
It was a valuable experience, and I'm grateful that we live in a time when we can challenge ourselves like this so easily.
Now, let's talk about what I actually built!
๐ ๏ธ The Design Behind type-tune
One architectural decision remained unchanged throughout the migration.
Scan / Plan / Apply
Consider a typical TypeScript project.
src/
โโโ features/
โ โโโ orders/
โ โ โโโ order-page.ts
โ โโโ dashboard/
โ โ โโโ dashboard.ts
โ โโโ reports/
โ โโโ reports.ts
Initially, a type belongs to the orders feature.
// features/orders/order-page.ts
export type OrderSummary = {
id: string;
total: number;
};
But as the application grows, other features start importing it.
// features/dashboard/dashboard.ts
import type { OrderSummary } from "../orders/order-page";
export function calculateRevenue(orders: OrderSummary[]) {
return orders.reduce((sum, order) => sum + order.total, 0);
}
// features/reports/reports.ts
import type { OrderSummary } from "../orders/order-page";
export function createReport(order: OrderSummary) {
return `${order.id}: ${order.total}`;
}
The type is still useful, but its original location may no longer be appropriate.
Tools like Knip help us remove unused code.
type-tune tackles a different problem: reorganizing types that are still in use.
๐ 1. Scan
pnpm exec type-tune scan --project tsconfig.json
type-tune analyzes exported type aliases, interfaces, references, and relevant dependencies to identify potential extraction candidates.
No source code is modified.
๐ 2. Plan
Finding a type that can be moved doesn't necessarily mean it should be moved.
That's why type-tune generates a reviewable plan.
pnpm exec type-tune plan \
--project tsconfig.json \
--out .type-tune/plan.json \
--markdown .type-tune/plan.md
It generates two files:
-
plan.jsonโ Candidate metadata and validation information. -
plan.mdโ A human-readable, editable plan.
Every candidate is ignored by default.
Here's a simplified example of plan.md:
- [ignore] <candidate-id> `OrderSummary`
- kind: `typeAlias`
- from: `src/features/orders/order-page.ts`
- to: `src/features/orders/types/order.ts`
You can approve the candidate and customize its destination.
- [ignore] <candidate-id> OrderSummary
+ [apply] <candidate-id> OrderSummary
- kind: typeAlias
- from: src/features/orders/order-page.ts
- - to: src/features/orders/types/order.ts
+ - to: src/domains/orders/types/order-summary.ts
Perhaps it belongs in a shared directory, a domain-specific module, or exactly where it is now.
That's an architectural decision.
You decide what moves and where.
๐ 3. Apply
Preview the selected changes:
pnpm exec type-tune apply \
--plan .type-tune/plan.json \
--markdown .type-tune/plan.md \
--dry-run
Then apply them:
pnpm exec type-tune apply \
--plan .type-tune/plan.json \
--markdown .type-tune/plan.md
The resulting project structure:
src/
โโโ domains/
โ โโโ orders/
โ โโโ types/
โ โโโ order-summary.ts โ Moved!
โโโ features/
โโโ orders/
โ โโโ order-page.ts
โโโ dashboard/
โ โโโ dashboard.ts
โโโ reports/
โโโ reports.ts
The type now lives in its new home.
// domains/orders/types/order-summary.ts
export type OrderSummary = {
id: string;
total: number;
};
Supported imports are updated automatically.
- import type { OrderSummary } from "../orders/order-page";
+ import type { OrderSummary } from "../../domains/orders/types/order-summary";
And the original module retains a compatibility re-export.
// features/orders/order-page.ts
export type { OrderSummary } from "../../domains/orders/types/order-summary";
type-tune also validates the rewrite using the TypeScript compiler and rolls back changes if normal validation fails.
You should still review the resulting diff and run your project-specific tests and builds.
๐งฉ Automate the Work, Not the Decisions
Why separate Scan, Plan, and Apply?
Because discovering opportunities, making architectural decisions, and executing changes are different responsibilities.
type-tune even supports optional AI-assisted review:
pnpm exec type-tune plan \
--project tsconfig.json \
--ai-review \
--ai-dry-run
AI can provide additional review notes, but it doesn't control the source code rewrite. The command above previews the AI review request without contacting a provider.
Interestingly, this is also how I want to work with AI in my own development.
Automate the tedious work without taking architectural decisions away from developers.
That's the philosophy behind type-tune.
๐ Give Your TypeScript Types a Better Home!
You can start by simply scanning your project.
npx type-tune scan --project tsconfig.json
No need to move anything yet. Just see what you find! ๐ธ
type-tune
Give shared TypeScript types a better home. ๐ธ
Scan. Review. Move. Validate.
type-tune is a Rust-powered CLI that finds shared TypeScript type aliases and interface declarations and helps move them without manually chasing imports.
It creates a reviewable plan, updates supported type imports and re-exports, and validates the rewrite with TypeScript. You decide what moves and where.
Guides for installation, the first scan, and the review workflow live in the official documentation. Releases are listed on GitHub Releases, and the package is type-tune on npm.
Why type-tune?
Types often start next to a component or utility, then end up shared across a project. Moving them later means tracking imports, local dependencies, and barrels by hand.
- Discover shared types with deterministic candidate IDs.
-
Review
plan.mdand choose the destination before making changes. - Rewrite supported type-only imports, aliases, and simple barrels while keeping compatibility re-exports at the originalโฆ
Feedback, ideas, issues, and contributions are always welcome!
And if you're a Rust developer, please teach this poor TypeScript cat how to become a competent crab. ๐น๐ฆ
Small. Simple. Useful. Built Together!
Thank you for reading! ๐๐

Top comments (22)
"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! ๐ฑ๐ฆ๐
๐๐
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. ๐ฑ๐
Thank you so much! ๐ธ๐
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.
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. ๐น๐ฆ
omg i gave you star and followed you i loved it so cute ๐๐
YAY!!! ๐ธ๐
Thank you so much for the star and the follow!!
Iโm really happy you liked it. ๐๐ฆโจ
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?
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. ๐ฆ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.
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. ๐น๐ฆ
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,
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. ๐โจ
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.
Good catch. ๐
Right now, type-tune does not walk TypeScript project references.
If the selected
tsconfighas non-emptyreferences, scan/plan/apply are rejected before any rewrite happens. Path aliases are supported, but final validation still runs against the selected--projectonly.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. ๐ฆ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?
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. ๐
I think porting a working tool is a brave way to learn a new language properly.
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. ๐น๐ฆ
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! ๐
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:
scanplanapply --dry-runI also tested a real
is-kitcheckout:scanplanThat 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()andpubinstead of just generating the code. Thatโs exactly the kind of habit I want to build.Thanks again for such a detailed comment! ๐