{"repo":"Aleph-Alpha/ts-rs","free":true,"listed":false,"github":"https://github.com/Aleph-Alpha/ts-rs","clone":"git clone https://github.com/Aleph-Alpha/ts-rs.git","description":"Generate TypeScript bindings from Rust types","language":"Rust","stars":1862,"topics":["code-generation","rust","types","rust-to-typescript","binding-generator","bindings","typescript"],"license":"MIT","category":"dev-tools","readme_excerpt":"ts-rs ts-rs Generate typescript type declarations from rust types Why? When building a web application in rust, data structures have to be shared between backend and frontend. Using this library, you can easily generate TypeScript bindings to your rust structs & enums so that you can keep your types in one place. ts-rs might also come in handy when working with webassembly. How? ts-rs exposes a single trait, TS . Using a derive macro, you can implement this interface for your types. Then, you can use this trait to obtain the TypeScript bindings. We recommend doing this in your tests. See the example and the docs. Get started When running cargo test or cargo test export bindings , the following TypeScript type will be exported to bindings/User.ts : Features - generate type declarations from rust structs - generate union declarations from rust enums - works with generic types - compatible with serde - generate necessary imports when exporting to multiple files - precise control over generated types If there's a type you're dealing with which doesn't implement TS , you can use either #[ts(as = \"..\")] or #[ts(type = \"..\")] , enable the appropriate cargo feature, or open a PR. Configuration When using #[ts(export)] on a type, ts-rs generates a test which writes the bindings for it to disk.\\ The following environment variables may be set to configure how and where : Variable Description Default -------------------------- -------------------------------------------------------------","default_branch":null,"files":null,"tree":[],"storefront":"/r/Aleph-Alpha","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/Aleph-Alpha/ts-rs/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}