Skip to main content

ts

Attribute Macro ts 

Source
#[ts]
Expand description

Generates TypeScript interface bindings from a Rust struct.

This attribute works identically to the upstream ts-macro attribute, allowing the struct to define a TypeScript interface with property bindings seamlessly mapped to Javascript functions.

It generates:

  1. A TypeScript interface string exposed as a custom wasm section
  2. Extensible bindings and trait implementations

The default behavior for field names is to convert to camelCase for Javascript conventions. However, you can opt-out by adding rename_all = "none":

#[ts(rename_all = "none")]
struct MyStruct {
    my_field_name: String, // Will remain "my_field_name" in TypeScript
}