Skip to main content

TypescriptType

Derive Macro TypescriptType 

Source
#[derive(TypescriptType)]
{
    // Attributes available to this derive:
    #[ts]
}
Expand description

为 Rust 类型定义生成 TypeScript 类型别名

§示例

use typescript_macros::TypescriptType;

#[derive(TypescriptType)]
struct User {
    id: u32,
    name: String,
    active: bool,
}

这将生成对应的 TypeScript 类型别名:

type User = {
    id: number;
    name: string;
    active: boolean;
};