Skip to content
Branch: master
Find file History
Pull request Compare This branch is 7 commits ahead of srijs:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests Export typescript_custom_section(s) from #[derive(TypescriptDefinition)] Nov 21, 2018
.gitignore
.travis.yml initial commit May 23, 2018
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md Colorful README. Jan 22, 2019

README.md

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.

You can’t perform that action at this time.