Skip to main content

TypescriptInterface

Derive Macro TypescriptInterface 

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

为 Rust 接口生成 TypeScript 接口定义

§示例

use typescript_macros::TypescriptInterface;

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

这将生成对应的 TypeScript 接口定义:

interface User {
    id: number;
    name: string;
    active: boolean;
}