#typescript #serde #struct #wasm-bindgen #definition #definitions #support

macro wasm-typescript-definition

serde support for exporting Typescript definitions using wasm-bindgen

5 releases

0.1.4 Dec 12, 2018
0.1.3 Dec 12, 2018
0.1.2 Nov 22, 2018
0.1.1 Nov 22, 2018
0.1.0 Nov 21, 2018
Download history 14/week @ 2019-01-21 11/week @ 2019-01-28 16/week @ 2019-02-04 11/week @ 2019-02-11 10/week @ 2019-02-18 8/week @ 2019-02-25 17/week @ 2019-03-04 14/week @ 2019-03-11 11/week @ 2019-03-18 18/week @ 2019-03-25 14/week @ 2019-04-01 11/week @ 2019-04-08 17/week @ 2019-04-15 18/week @ 2019-04-22 17/week @ 2019-04-29

117 downloads per month

MIT/Apache

25KB
271 lines

wasm-typescript-definition

Exports serde-serializable structs and enums to Typescript definitions when used with wasm-bindgen.

#[derive(Serialize, TypescriptDefinition)]
enum Enum {
    #[allow(unused)]
    V1 {
        #[serde(rename = "Foo")]
        foo: bool,
    },
    #[allow(unused)]
    V2 {
        #[serde(rename = "Bar")]
        bar: i64,
        #[serde(rename = "Baz")]
        baz: u64,
    },
    #[allow(unused)]
    V3 {
        #[serde(rename = "Quux")]
        quux: String,
    },
}

With the patched version of wasm-bindgen that supports typescript_custom_section (TODO), this will output in your .d.ts definition file:

export type Enum = 
    | {"tag": "V1", "fields": { "Foo": boolean, }, }
    | {"tag": "V2", "fields": { "Bar": number, "Baz": number, }, }
    | {"tag": "V3", "fields": { "Quux": string, }, }
    ;

Credit

Forked from rust-serde-schema by @srijs.

License

MIT or Apache-2.0, at your option.

Dependencies

~1MB
~26K SLoC