| Crates.io | ts-macro |
| lib.rs | ts-macro |
| version | 1.0.1 |
| created_at | 2025-04-17 05:55:13.592608+00 |
| updated_at | 2025-04-17 06:00:07.507013+00 |
| description | Generate TypeScript interface bindings from a Rust struct. |
| homepage | |
| repository | https://github.com/ryangoree/wasm-utils-rs |
| max_upload_size | |
| id | 1637268 |
| size | 662,784 |
ts-macro is a Rust procedural macro crate designed to generate TypeScript
interface bindings for Rust structs. This crate simplifies the process of
creating seamless TypeScript bindings for Rust code, making it easier to work
with WebAssembly and JavaScript ecosystems.

wasm-bindgen
projects and supports all JavaScript standard, built-in objects via js-sys.#[ts] attribute to your struct and get
TypeScript interfaces and field getter bindings—no manual parsing required.ts
attribute to each struct individually.extends argument.#[ts]
struct Token {
symbol: String,
/// @default 18
decimals: Option<u8>,
total_supply: BigInt,
}
#[wasm_bindgen]
pub fn handle_token(token: IToken) {
let symbol = token.symbol();
let decimals = token.decimals().unwrap_or(18.into());
let total_supply = token.total_supply();
let token = token.parse();
let token: Token = token.into();
}
This generates the following TypeScript interface:
interface IToken {
symbol: string;
/**
* @default 18
*/
decimals?: number | undefined;
totalSupply: bigint;
}
#[ts]
struct Order {
account: String,
amount: BigInt,
token: IToken, // Binding to the `Token` struct
}
You can customize the TypeScript interface using the ts attribute:
#[ts]
struct Params {
#[ts(name = "specialCASING")]
special_casing: String,
#[ts(type = "`0x${string}`")]
special_format: String,
optional_field_and_value: Option<String>,
#[ts(optional = false)]
optional_value: Option<String>,
#[ts(optional = true)]
optional_field: String,
}
This generates:
interface IParams {
specialCASING: string;
specialFormat: `0x${string}`;
optionalFieldAndValue?: string | undefined;
optionalValue: string | undefined;
optionalField?: string;
}
#[ts(name = JsToken)]
struct Token {
symbol: String,
decimals: Number,
total_supply: BigInt,
}
#[ts(name = JsShareToken, extends = JsToken)]
struct ShareToken {
price: BigInt,
}
This generates:
interface JsToken {
// ...
}
interface JsShareToken extends JsToken {
// ...
}
ts-rs – Generates TypeScript
definition files from Rust structs and enums, but isn’t integrated with
wasm-bindgen and doesn’t include bindings to parse the type from a JS value.tauri-specta – Solves the same problem and
more, but is specifically for Tauri app backends.tsify – Same idea, but is built on
serde-wasm-bindgen which
doesn’t parse JS types, so API types are limited.