Skip to main content

typescript_namespace

Attribute Macro typescript_namespace 

Source
#[typescript_namespace]
Expand description

为 Rust 模块生成 TypeScript 命名空间

§示例

use typescript_macros::typescript_namespace;

#[typescript_namespace("utils")]
mod utils {
    pub fn add(a: u32, b: u32) -> u32 {
        a + b
    }

    pub struct Point {
        pub x: f64,
        pub y: f64,
    }
}

这将生成对应的 TypeScript 命名空间:

namespace utils {
    export function add(a: number, b: number): number;
     
    export interface Point {
        x: number;
        y: number;
    }
}