# ts-rs

A Rust derive macro that generates matching TypeScript type declarations from Rust structs and enums, for keeping shared data types in sync between a Rust backend and a TypeScript frontend.

ts-rs exposes a TS trait that a derive macro implements for Rust structs and enums, generating TypeScript type declarations from them, including generic types and enum-to-union-type conversion, compatible with Serde. Running the project's tests, such as cargo test export_bindings, writes the generated TypeScript to a bindings directory as a side effect of the test.

Environment variables configure how and where bindings are exported: the output directory, the file extension used in generated import statements, and the binding used for large integer types such as i64 and u64. Bindings can also be exported programmatically, without running tests, through export_all, export and export_to_string.

A type without a TS implementation can be handled with a ts(as) or ts(type) attribute, or an appropriate cargo feature.

Website: https://github.com/Aleph-Alpha/ts-rs
