Tsify
Tsify is a library for generating TypeScript definitions from Rust code.
Using this with wasm-bindgen will automatically output the types to .d.ts.
Inspired by typescript-definitions and ts-rs.
Example
[]
= "0.1"
= { = "1.0", = ["derive"] }
= { = "0.2", = ["serde-serialize"] }
use ;
use Tsify;
use *;
Will generate the following .d.ts file:
/* tslint:disable */
/* eslint-disable */
/**
* @returns {Point}
*/
export function into_js(): Point;
/**
* @param {Point} point
*/
export function from_js(point: Point): void;
export type Point = { x: number; y: number };
Attributes
Tsify container attributes
into_wasm_abiimplementsIntoWasmAbiandOptionIntoWasmAbi. This can be converted directly from Rust to JS via JSON.from_wasm_abiimplementsFromWasmAbiandOptionFromWasmAbi. This is the opposite operation of the above.
Tsify field attributes
typeoptional
Serde attributes
renamerename-alltagcontentuntaggedskipskip_serializingskip_deserializingskip_serializing_if = "Option::is_none"flattendefaulttransparent
Type Override
use Tsify;
Generated type:
export type Foo = { x: 0 | 1 | 2 };
Optional Properties
Generated type:
export type Optional = { a?: number; b?: string; c?: number };
Type Aliases
use ;
;
type Bar = ;
Generated type:
export type Foo<T> = T;
export type Bar = Foo<number>;
Crate Features
wasm-bindgen-impl(default) Generatetypescript_custom_sectionandRust Type conversions