ts-rs
ts-rs is a Rust library that automatically generates TypeScript type definitions from Rust structs and enums using a derive macro. It eliminates manual type duplication when building full-stack applications with Rust backends and TypeScript frontends, supporting generics, serde compatibility, and multi-file exports.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | Aleph-Alpha/ts-rs |
| Owner | Aleph-Alpha |
| Primary language | Rust |
| License | MIT — OSI-approved |
| Stars | 1.8k |
| Forks | 166 |
| Open issues | 32 |
| Latest release | v12.0.0 (2026-01-31) |
| Last updated | 2026-06-17 |
| Source | https://github.com/Aleph-Alpha/ts-rs |
What ts-rs is
ts-rs provides a derive macro implementing the TS trait, enabling compile-time code generation of TypeScript declarations from Rust types. It parses serde attributes (rename, tag, flatten, etc.), handles generic types, supports large integers via configurable bindings, and exports bindings as test artifacts or programmatically via TS::export APIs.
Get the ts-rs source
Clone the repository and explore it locally.
git clone https://github.com/Aleph-Alpha/ts-rs.gitcd ts-rs# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Bindings are generated at test time (via #[ts(export)] or cargo test). Ensure CI/CD runs tests before packaging frontend code, or use programmatic TS::export APIs in build scripts.
- Configure TS_RS_EXPORT_DIR, TS_RS_LARGE_INT, and TS_RS_IMPORT_EXTENSION in .cargo/config.toml to persist settings across environments and avoid mismatches between Rust and TypeScript integer representations.
- Enable serde-compat feature (default) to parse serde rename/tag/flatten attributes; verify generated types match your serialization strategy (especially for enums with custom tagging).
- For unsupported types, use #[ts(as=...)] or #[ts(type=...)] attributes; enable appropriate cargo features (chrono-impl, uuid-impl, etc.) for common third-party types.
- Test generated bindings in frontend code; ts-rs generates correct syntax but does not validate whether types integrate with existing TypeScript codebases or bundler setups.
When to avoid it — and what to weigh
- Standalone Frontend or Backend Teams — If teams manage frontend and backend independently without shared codebase, manual type definitions or separate API schema tools (OpenAPI, GraphQL) are more practical.
- Non-serde Serialization Formats — Projects using custom serialization (protobuf, avro, bincode-specific) may require feature flags or workarounds; unsupported types demand manual fallbacks via #[ts(as=)] or #[ts(type=)].
- Complex Conditional Type Logic — TypeScript generics, conditional types, or advanced type inference patterns cannot be expressed via Rust struct derives; generated types will be simpler than hand-written equivalents.
- Strict CI/CD Type Verification — If frontend CI must verify bindings before deployment, the test-based export model requires careful orchestration; programmatic export APIs mitigate this but add complexity.
License & commercial use
Licensed under MIT (MIT License), a permissive OSI-approved open-source license.
MIT license permits commercial use, modification, and distribution with minimal restrictions (retain copyright/license notice). No proprietary terms or patent clauses present. Safe for commercial projects; no license review required for standard commercial deployment.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
ts-rs is a code generation tool with no runtime attack surface. Generated TypeScript bindings are static type definitions (no execution). Verify: Rust crate provenance (crates.io), build script behavior if using programmatic export, and that generated bindings do not expose sensitive data structures unintentionally. No security audit data provided.
Alternatives to consider
tsync (Rust + TypeScript)
Similar derive-based approach; compare feature coverage, serde support, and ecosystem maturity. Check if tsync meets your specific type requirements (e.g., union vs. enum handling).
OpenAPI / GraphQL Schema Generation
Language-agnostic schema-first approach for API-driven type generation. Suitable if backend and frontend are decoupled or multiple clients exist; steeper setup but broader tooling support.
Manual Type Definition + Runtime Validation (zod, joi)
Explicit control over type mapping and validation logic. Use if types are simple, teams are separate, or advanced TS type features are critical. Higher maintenance burden.
Build on ts-rs with DEV.co software developers
Our engineers can help you set up type-safe Rust-to-TypeScript pipelines, optimize build processes, and ensure CI/CD alignment. Contact us for a technical consultation.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
ts-rs FAQ
Does ts-rs support circular/recursive type references?
Can I customize the generated TypeScript syntax (e.g., interfaces vs. types)?
What happens if a Rust type field is added/removed after bindings are generated?
Does ts-rs work with non-monorepo setups (separate frontend/backend repos)?
Custom software development services
DEV.co is a software development agency delivering custom software development services to companies building on open source. Our software developers and web developers design, integrate, and ship production systems — spanning web development, APIs, AI, data, and cloud. If ts-rs is part of your ai coding agents roadmap, our team can implement, customize, migrate, and maintain it.
Need Help Integrating ts-rs Into Your Stack?
Our engineers can help you set up type-safe Rust-to-TypeScript pipelines, optimize build processes, and ensure CI/CD alignment. Contact us for a technical consultation.