Loading TypeScript to Rust Converter...
How to Convert TypeScript to Rust - Step by Step Guide
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:
How the Types Are Mapped
The converter reads your TypeScript with a real TypeScript parser, then writes the matching Rust types:
string becomes String, boolean becomes bool, and number becomes f64 (so both whole numbers and decimals from JSON fit)T[] becomes Vec<T>, a nested object literal becomes its own named struct, and Record or an index signature becomes a HashMapprop?) becomes Option, and a union of string literals becomes a Rust enum with serde rename attributesAdjust the Options
A few toggles above the editor shape the generated code:
pub or keep them privatenumber as f64, or map it to i64 when your numbers are always whole (serde will then reject decimals)Copy or Download Your Rust Code
Take the generated structs straight into your project:
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.
Related Tools
JSON to Rust
Convert JSON data to Rust structs with serde Serialize/Deserialize traits
JSON Schema to Rust
Generate Rust types from JSON Schema with validation
YAML to Rust
Convert YAML configuration to Rust structs with serde
TOML to Rust
Convert TOML configuration to Rust config structs
XML to Rust
Convert XML data to Rust structs with serde serialization support
CSV to Rust
Convert CSV data to Rust structs with field mapping