DEV Community

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

Posted on AI-assisted

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

Inspired by a DHH video to port 20k lines

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.

GitHub logo necoz-oss / type-tune

A Rust-powered CLI to find shared TypeScript types and move them safely. ๐Ÿฆ€

type-tune

Animated type-tune logo

Test Docs MIT License

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.md and 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[];
};
Enter fullscreen mode Exit fullscreen mode

Into something like this:

enum CandidateKind {
    TypeAlias,
    Interface,
}

struct Candidate {
    id: String,
    name: String,
    kind: CandidateKind,
    referrers: Vec<String>,
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

Another option is to clone the value.

print_name(name.clone());
println!("{}", name); // OK
Enter fullscreen mode Exit fullscreen mode

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() {
    // ...
}
Enter fullscreen mode Exit fullscreen mode

But if the function is only used within the same crate, exposing it publicly may be unnecessary.

pub(crate) fn resolve_destination() {
    // ...
}
Enter fullscreen mode Exit fullscreen mode

And if it's only used within its own module, it can remain private.

fn resolve_destination() {
    // ...
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Initially, a type belongs to the orders feature.

// features/orders/order-page.ts

export type OrderSummary = {
  id: string;
  total: number;
};
Enter fullscreen mode Exit fullscreen mode

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);
}
Enter fullscreen mode Exit fullscreen mode
// features/reports/reports.ts

import type { OrderSummary } from "../orders/order-page";

export function createReport(order: OrderSummary) {
  return `${order.id}: ${order.total}`;
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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`
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Then apply them:

pnpm exec type-tune apply \
  --plan .type-tune/plan.json \
  --markdown .type-tune/plan.md
Enter fullscreen mode Exit fullscreen mode

The resulting project structure:

src/
โ”œโ”€โ”€ domains/
โ”‚   โ””โ”€โ”€ orders/
โ”‚       โ””โ”€โ”€ types/
โ”‚           โ””โ”€โ”€ order-summary.ts  โ† Moved!
โ””โ”€โ”€ features/
    โ”œโ”€โ”€ orders/
    โ”‚   โ””โ”€โ”€ order-page.ts
    โ”œโ”€โ”€ dashboard/
    โ”‚   โ””โ”€โ”€ dashboard.ts
    โ””โ”€โ”€ reports/
        โ””โ”€โ”€ reports.ts
Enter fullscreen mode Exit fullscreen mode

The type now lives in its new home.

// domains/orders/types/order-summary.ts

export type OrderSummary = {
  id: string;
  total: number;
};
Enter fullscreen mode Exit fullscreen mode

Supported imports are updated automatically.

- import type { OrderSummary } from "../orders/order-page";
+ import type { OrderSummary } from "../../domains/orders/types/order-summary";
Enter fullscreen mode Exit fullscreen mode

And the original module retains a compatibility re-export.

// features/orders/order-page.ts

export type { OrderSummary } from "../../domains/orders/types/order-summary";
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

No need to move anything yet. Just see what you find! ๐Ÿ˜ธ

GitHub logo necoz-oss / type-tune

A Rust-powered CLI to find shared TypeScript types and move them safely. ๐Ÿฆ€

type-tune

Animated type-tune logo

Test Docs MIT License

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.md and 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 (2)

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. ๐Ÿˆ๐Ÿฆ€โœจ