Skip to content

If you use wasm-bindgen, this crate exports TypeScript definitions from any serde-serializable struct.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

tcr/wasm-typescript-definition

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

If you use wasm-bindgen, this crate exports TypeScript definitions from any serde-serializable struct.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%