{"id":13838464,"url":"https://github.com/madonoharu/tsify","last_synced_at":"2025-12-29T23:59:43.488Z","repository":{"id":37033410,"uuid":"475366638","full_name":"madonoharu/tsify","owner":"madonoharu","description":"A library for generating TypeScript definitions from rust code.","archived":false,"fork":false,"pushed_at":"2024-02-02T10:18:20.000Z","size":78,"stargazers_count":295,"open_issues_count":36,"forks_count":41,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-09T23:24:45.717Z","etag":null,"topics":["rust","serde","typescript","wasm","wasm-bindgen","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/madonoharu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-29T09:15:14.000Z","updated_at":"2024-08-09T20:58:48.000Z","dependencies_parsed_at":"2024-06-19T17:52:33.999Z","dependency_job_id":null,"html_url":"https://github.com/madonoharu/tsify","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madonoharu%2Ftsify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madonoharu%2Ftsify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madonoharu%2Ftsify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madonoharu%2Ftsify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madonoharu","download_url":"https://codeload.github.com/madonoharu/tsify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225653891,"owners_count":17502939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","serde","typescript","wasm","wasm-bindgen","webassembly"],"created_at":"2024-08-04T15:01:58.362Z","updated_at":"2025-12-29T23:59:43.482Z","avatar_url":"https://github.com/madonoharu.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Tsify\n\nTsify is a library for generating TypeScript definitions from Rust code.\n\nUsing this with [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) will automatically output the types to `.d.ts`.\n\nInspired by [`typescript-definitions`](https://github.com/arabidopsis/typescript-definitions) and [`ts-rs`](https://github.com/Aleph-Alpha/ts-rs).\n\n## Example\n\n\u003cdetails\u003e\n\u003csummary\u003e\nClick to show Cargo.toml.\n\u003c/summary\u003e\n\n```toml\n[dependencies]\ntsify = \"0.5.5\"\nserde = { version = \"1.0\", features = [\"derive\"] }\nwasm-bindgen = { version = \"0.2\" }\n```\n\n\u003c/details\u003e\n\n```rust\nuse serde::{Deserialize, Serialize};\nuse tsify::Tsify;\nuse wasm_bindgen::prelude::*;\n\n#[derive(Tsify, Serialize, Deserialize)]\n#[tsify(into_wasm_abi, from_wasm_abi)]\npub struct Point {\n    x: i32,\n    y: i32,\n}\n\n#[wasm_bindgen]\npub fn into_js() -\u003e Point {\n    Point { x: 0, y: 0 }\n}\n\n#[wasm_bindgen]\npub fn from_js(point: Point) {}\n```\n\nWill generate the following `.d.ts` file:\n\n```ts\n/* tslint:disable */\n/* eslint-disable */\n/**\n * @returns {Point}\n */\nexport function into_js(): Point;\n/**\n * @param {Point} point\n */\nexport function from_js(point: Point): void;\nexport interface Point {\n    x: number;\n    y: number;\n}\n```\n\nThis is the behavior due to [`typescript_custom_section`](https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/on-rust-exports/typescript_custom_section.html) and [`Rust Type conversions`](https://rustwasm.github.io/docs/wasm-bindgen/contributing/design/rust-type-conversions.html).\n\n## Crate Features\n\n-   `json` (default) enables serialization through [`serde_json`](https://github.com/serde-rs/json).\n-   `js` enables serialization through [`serde-wasm-bindgen`](https://github.com/cloudflare/serde-wasm-bindgen) and generates the appropriate types for it. This will be the default in future versions.\n\n## Attributes\n\nTsify container attributes\n\n-   `into_wasm_abi` implements `IntoWasmAbi` and `OptionIntoWasmAbi`. This can be converted directly from Rust to JS via `serde_json` or `serde-wasm-bindgen`.\n-   `from_wasm_abi` implements `FromWasmAbi` and `OptionFromWasmAbi`. This is the opposite operation of the above.\n-   `namespace` generates a namespace for the enum variants.\n-   `type` overrides at the container level.\n-   `type_params` overrides params at the container level.\n\n[Serializer configuration options](https://github.com/RReverser/serde-wasm-bindgen?tab=readme-ov-file#serializer-configuration-options)\n-   `missing_as_null` \n-   `hashmap_as_object`\n-   `large_number_types_as_bigints`\n\nTsify field attributes\n\n-   `type`\n-   `type_params`\n-   `optional`\n\nSerde attributes\n\n-   `rename`\n-   `rename-all`\n-   `tag`\n-   `content`\n-   `untagged`\n-   `skip`\n-   `skip_serializing`\n-   `skip_deserializing`\n-   `skip_serializing_if = \"Option::is_none\"`\n-   `flatten`\n-   `default`\n-   `transparent`\n\n## Type Override\n\n```rust\nuse tsify::Tsify;\n\n#[derive(Tsify)]\npub struct Foo {\n    #[tsify(type = \"0 | 1 | 2\")]\n    x: i32,\n}\n```\n\nGenerated type:\n\n```ts\nexport interface Foo {\n    x: 0 | 1 | 2;\n}\n```\n\n## Optional Properties\n\n```rust\n#[derive(Tsify)]\nstruct Optional {\n    #[tsify(optional)]\n    a: Option\u003ci32\u003e,\n    #[serde(skip_serializing_if = \"Option::is_none\")]\n    b: Option\u003cString\u003e,\n    #[serde(default)]\n    c: i32,\n}\n```\n\nGenerated type:\n\n```ts\nexport interface Optional {\n    a?: number;\n    b?: string;\n    c?: number;\n}\n```\n\n## Enum\n\n```rust\n#[derive(Tsify)]\nenum Color {\n    Red,\n    Blue,\n    Green,\n    Rgb(u8, u8, u8),\n    Hsv {\n        hue: f64,\n        saturation: f64,\n        value: f64,\n    },\n}\n```\n\nGenerated type:\n\n```ts\nexport type Color =\n    | \"Red\"\n    | \"Blue\"\n    | \"Green\"\n    | { Rgb: [number, number, number] }\n    | { Hsv: { hue: number; saturation: number; value: number } };\n```\n\n## Enum with namespace\n\n```rust\n#[derive(Tsify)]\n#[tsify(namespace)]\nenum Color {\n    Red,\n    Blue,\n    Green,\n    Rgb(u8, u8, u8),\n    Hsv {\n        hue: f64,\n        saturation: f64,\n        value: f64,\n    },\n}\n```\n\nGenerated type:\n\n```ts\ndeclare namespace Color {\n    export type Red = \"Red\";\n    export type Blue = \"Blue\";\n    export type Green = \"Green\";\n    export type Rgb = { Rgb: [number, number, number] };\n    export type Hsv = {\n        Hsv: { hue: number; saturation: number; value: number };\n    };\n}\n\nexport type Color =\n    | \"Red\"\n    | \"Blue\"\n    | \"Green\"\n    | { Rgb: [number, number, number] }\n    | { Hsv: { hue: number; saturation: number; value: number } };\n```\n\n## Type Aliases\n\n```rust\nuse tsify::{declare, Tsify};\n\n#[derive(Tsify)]\nstruct Foo\u003cT\u003e(T);\n\n#[declare]\ntype Bar = Foo\u003ci32\u003e;\n```\n\nGenerated type:\n\n```ts\nexport type Foo\u003cT\u003e = T;\nexport type Bar = Foo\u003cnumber\u003e;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadonoharu%2Ftsify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadonoharu%2Ftsify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadonoharu%2Ftsify/lists"}