{"id":25858524,"url":"https://github.com/aleph-alpha/ts-rs","last_synced_at":"2025-05-12T13:28:03.360Z","repository":{"id":39652509,"uuid":"321690304","full_name":"Aleph-Alpha/ts-rs","owner":"Aleph-Alpha","description":"Generate TypeScript bindings from Rust types","archived":false,"fork":false,"pushed_at":"2025-04-05T22:47:14.000Z","size":870,"stargazers_count":1366,"open_issues_count":16,"forks_count":126,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-08T23:11:37.019Z","etag":null,"topics":["binding-generator","bindings","code-generation","rust","rust-to-typescript","types","typescript"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aleph-Alpha.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2020-12-15T14:21:32.000Z","updated_at":"2025-05-06T00:53:21.000Z","dependencies_parsed_at":"2024-01-13T19:19:05.599Z","dependency_job_id":"fd5bc68f-8e64-4e7b-b801-ad229c81a649","html_url":"https://github.com/Aleph-Alpha/ts-rs","commit_stats":{"total_commits":222,"total_committers":24,"mean_commits":9.25,"dds":0.6576576576576576,"last_synced_commit":"b4ba8b81fd8833296e99285eae7608864c52e51e"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aleph-Alpha%2Fts-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aleph-Alpha%2Fts-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aleph-Alpha%2Fts-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aleph-Alpha%2Fts-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aleph-Alpha","download_url":"https://codeload.github.com/Aleph-Alpha/ts-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253747267,"owners_count":21957731,"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":["binding-generator","bindings","code-generation","rust","rust-to-typescript","types","typescript"],"created_at":"2025-03-01T20:20:21.757Z","updated_at":"2025-05-12T13:28:03.335Z","avatar_url":"https://github.com/Aleph-Alpha.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-rs\n\n\u003ch1 align=\"center\" style=\"padding-top: 0; margin-top: 0;\"\u003e\n\u003cimg width=\"150px\" src=\"https://raw.githubusercontent.com/Aleph-Alpha/ts-rs/main/logo.png\" alt=\"logo\"\u003e\n\u003cbr/\u003e\nts-rs\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\nGenerate typescript type declarations from rust types\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003c!-- Github Actions --\u003e\n\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/Aleph-Alpha/ts-rs/test.yml?branch=main\" alt=\"actions status\" /\u003e\n\u003ca href=\"https://crates.io/crates/ts-rs\"\u003e\n\u003cimg src=\"https://img.shields.io/crates/v/ts-rs.svg?style=flat-square\"\nalt=\"Crates.io version\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://docs.rs/ts-rs\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square\"\nalt=\"docs.rs docs\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://crates.io/crates/ts-rs\"\u003e\n\u003cimg src=\"https://img.shields.io/crates/d/ts-rs.svg?style=flat-square\"\nalt=\"Download\" /\u003e\n\u003c/a\u003e\n\u003c/div\u003e\n\n### Why?\nWhen building a web application in rust, data structures have to be shared between backend and frontend.\nUsing this library, you can easily generate TypeScript bindings to your rust structs \u0026 enums so that you can keep your\ntypes in one place.\n\nts-rs might also come in handy when working with webassembly.\n\n### How?\nts-rs exposes a single trait, `TS`. Using a derive macro, you can implement this interface for your types.\nThen, you can use this trait to obtain the TypeScript bindings.\nWe recommend doing this in your tests.\n[See the example](https://github.com/Aleph-Alpha/ts-rs/blob/main/example/src/lib.rs) and [the docs](https://docs.rs/ts-rs/latest/ts_rs/).\n\n### Get started\n```toml\n[dependencies]\nts-rs = \"10.1\"\n```\n\n```rust\nuse ts_rs::TS;\n\n#[derive(TS)]\n#[ts(export)]\nstruct User {\n    user_id: i32,\n    first_name: String,\n    last_name: String,\n}\n```\n\nWhen running `cargo test` or `cargo test export_bindings`, the TypeScript bindings will be exported to the file `bindings/User.ts`\nand will contain the following code:\n\n```ts\nexport type User = { user_id: number, first_name: string, last_name: string, };\n```\n\n### Features\n- generate type declarations from rust structs\n- generate union declarations from rust enums\n- inline types\n- flatten structs/types\n- generate necessary imports when exporting to multiple files\n- serde compatibility\n- generic types\n- support for ESM imports\n\n### cargo features\n| **Feature**        | **Description**                                                                                                                                                                                           |\n|:-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| serde-compat       | **Enabled by default** \u003cbr/\u003eSee the *\"serde compatibility\"* section below for more information.                                                                                                           |\n| format             | Enables formatting of the generated TypeScript bindings. \u003cbr/\u003eCurrently, this unfortunately adds quite a few dependencies.                                                                                |\n| no-serde-warnings  | By default, warnings are printed during build if unsupported serde attributes are encountered. \u003cbr/\u003eEnabling this feature silences these warnings.                                                        |\n| import-esm         | When enabled,`import` statements in the generated file will have the `.js` extension in the end of the path to conform to the ES Modules spec. \u003cbr/\u003e Example: `import { MyStruct } from \"./my_struct.js\"` |\n| serde-json-impl    | Implement `TS` for types from *serde_json*                                                                                                                                                                |\n| chrono-impl        | Implement `TS` for types from *chrono*                                                                                                                                                                    |\n| bigdecimal-impl    | Implement `TS` for types from *bigdecimal*                                                                                                                                                                |\n| url-impl           | Implement `TS` for types from *url*                                                                                                                                                                       |\n| uuid-impl          | Implement `TS` for types from *uuid*                                                                                                                                                                      |\n| bson-uuid-impl     | Implement `TS` for *bson::oid::ObjectId* and *bson::uuid*                                                                                                                                                 |\n| bytes-impl         | Implement `TS` for types from *bytes*                                                                                                                                                                     |\n| indexmap-impl      | Implement `TS` for types from *indexmap*                                                                                                                                                                  |\n| ordered-float-impl | Implement `TS` for types from *ordered_float*                                                                                                                                                             |\n| heapless-impl      | Implement `TS` for types from *heapless*                                                                                                                                                                  |\n| semver-impl        | Implement `TS` for types from *semver*                                                                                                                                                                    |\n| smol_str-impl      | Implement `TS` for types from *smol_str*                                                                                                                                                                    |\n| tokio-impl         | Implement `TS` for types from *tokio*                                                                                                                                                                    |\n\n\u003cbr/\u003e\n\nIf there's a type you're dealing with which doesn't implement `TS`, use either\n`#[ts(as = \"..\")]` or `#[ts(type = \"..\")]`, or open a PR.\n\n### `serde` compatability\nWith the `serde-compat` feature (enabled by default), serde attributes can be parsed for enums and structs.\nSupported serde attributes:\n- `rename`\n- `rename-all`\n- `rename-all-fields`\n- `tag`\n- `content`\n- `untagged`\n- `skip`\n- `flatten`\n- `default`\n\nNote: `skip_serializing` and `skip_deserializing` are ignored. If you wish to exclude a field\nfrom the generated type, but cannot use `#[serde(skip)]`, use `#[ts(skip)]` instead.\n\nWhen ts-rs encounters an unsupported serde attribute, a warning is emitted, unless the feature `no-serde-warnings` is enabled.\n\n### Contributing\nContributions are always welcome!\nFeel free to open an issue, discuss using GitHub discussions or open a PR.\n[See CONTRIBUTING.md](https://github.com/Aleph-Alpha/ts-rs/blob/main/CONTRIBUTING.md)\n\n### MSRV\nThe Minimum Supported Rust Version for this crate is 1.78.0\n\nLicense: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleph-alpha%2Fts-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleph-alpha%2Fts-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleph-alpha%2Fts-rs/lists"}