Skip to main content

ts

Attribute Macro ts 

Source
#[ts]
Expand description

Generates TypeScript type aliases and wasm-bindgen ABI trait implementations for Rust items.

This attribute can be applied to:

  1. Structs: Generates a TypeScript interface and property bindings.
  2. Enums: Automatically applies #[wasm_bindgen] (supports C-style enums).
  3. Type Aliases: Generates a TypeScript type alias and a typed function wrapper.
  4. Impl Blocks: Generates a typed function wrapper for a call method.

ยงExamples

Struct Usage

โ“˜
#[ts(rename_all = "camelCase")]
struct MyStruct {
    field_name: String,
}

Enum Usage

โ“˜
#[ts]
enum Status { Active, Inactive }

Function Wrapper Usage

โ“˜
#[ts]
pub type OnReady = fn(msg: String);

#[ts]
struct AppFunctions {
    on_ready: OnReady,
}