Loading TypeScript to Rust Converter...

How to Convert TypeScript to Rust - Step by Step Guide

Step 1

Input Your TypeScript Code

Add your TypeScript interfaces, type aliases or enums so the converter can generate Rust code. There are three ways to get your code in:

•
Paste directly: copy your interface or type definitions and paste them into the input editor
•
Upload a file: click "Upload" to pick a .ts or .tsx file from your project
•
Try the sample: click "Sample" to load an example and see how the output is shaped
Step 2

How the Types Are Mapped

The converter reads your TypeScript with a real TypeScript parser, then writes the matching Rust types:

•
Primitives: string becomes String, boolean becomes bool, and number becomes f64 (so both whole numbers and decimals from JSON fit)
•
Arrays and objects: T[] becomes Vec<T>, a nested object literal becomes its own named struct, and Record or an index signature becomes a HashMap
•
Optionals and unions: an optional field (prop?) becomes Option, and a union of string literals becomes a Rust enum with serde rename attributes
Step 3

Adjust the Options

A few toggles above the editor shape the generated code:

•
Field visibility: make the struct fields pub or keep them private
•
Derive traits: pick from Debug, Clone, Serialize, Deserialize, PartialEq, Eq and Default. Eq is left off any type with a floating-point field, since that cannot derive Eq
•
Number mapping: keep number as f64, or map it to i64 when your numbers are always whole (serde will then reject decimals)
Step 4

Copy or Download Your Rust Code

Take the generated structs straight into your project:

•
Copy to clipboard: one click to paste the Rust into your editor
•
Download as .rs: save the output as a Rust source file
•
Ready for serde_json: add serde and serde_json to Cargo.toml and the structs deserialize JSON that matches your TypeScript

Frequently Asked Questions

How are TypeScript types mapped to Rust?

string becomes String, boolean becomes bool, and number becomes f64 (TypeScript has one number type, and f64 accepts both whole numbers and decimals from JSON). Arrays become Vec, a plain object literal becomes its own named struct, and an optional property (prop?) becomes Option. A union of string literals becomes a Rust enum, and Record or an index signature becomes a HashMap keyed by String.

Can the converter handle union types?

A union of string literals, such as "admin" | "user" | "guest", becomes a Rust enum with a serde rename on each variant. A type combined with null or undefined, like string | null, becomes Option of that type. A union of genuinely different types, such as string | number, has no single Rust type, so it becomes serde_json::Value and the output adds a note so you can model it by hand.

How do I use the generated Rust with a TypeScript frontend?

Add serde and serde_json to your Cargo.toml. Deserialize JSON coming from TypeScript with serde_json::from_str, and serialize Rust values back with serde_json::to_string. The original property names are preserved through serde rename attributes, so the JSON field names stay the same on both sides.

How are camelCase field names handled?

camelCase names become snake_case to follow Rust style, and the original name is kept with a #[serde(rename = "...")] attribute so JSON still round-trips. A name that clashes with a Rust keyword becomes a raw identifier (type becomes r#type); the few keywords that cannot be raw, like self, get a trailing underscore instead. Dashed or quoted keys such as "first-name" are cleaned up and renamed the same way.

Are TypeScript generics supported?

Array<T> and T[] both become Vec<T>, and Record<string, V> becomes a HashMap. A bare type parameter, like T inside interface Box<T>, has no fixed shape, so it becomes serde_json::Value with a note. Conditional, mapped and intersection types, along with function and Promise types, are also mapped to serde_json::Value rather than guessed.

Is it free, and where does my code go?

It is free, and the whole conversion runs in your browser. The TypeScript you paste is never uploaded and nothing is kept, so reloading the page starts with an empty editor.