DEV.co
AI Coding Agents · Aleph-Alpha

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.

Source: GitHub — github.com/Aleph-Alpha/ts-rs
1.8k
GitHub stars
166
Forks
Rust
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
RepositoryAleph-Alpha/ts-rs
OwnerAleph-Alpha
Primary languageRust
LicenseMIT — OSI-approved
Stars1.8k
Forks166
Open issues32
Latest releasev12.0.0 (2026-01-31)
Last updated2026-06-17
Sourcehttps://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.

Quickstart

Get the ts-rs source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/Aleph-Alpha/ts-rs.gitcd ts-rs# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Full-stack Rust + TypeScript Web Applications

Maintain type safety across backend (Rust) and frontend (TypeScript) in monorepos or tightly-coupled services. Reduces serialization bugs and keeps shared data structures synchronized.

WebAssembly Projects

Generate TypeScript bindings for Rust types exposed via wasm-bindgen, ensuring type consistency between WASM modules and JavaScript consumers.

API Clients and SDK Generation

Automatically create TypeScript client types from Rust API data models, useful for REST/GraphQL APIs or RPC services where clients need precise type coverage.

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.

SignalAssessment
MaintenanceActive
DocumentationStrong
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

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.

Software development agency

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.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related 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?
Not explicitly documented. Recursive Rust types may cause issues in TypeScript; check GitHub issues or repo discussions for workarounds. Feature request or PR may be needed if unsupported.
Can I customize the generated TypeScript syntax (e.g., interfaces vs. types)?
ts-rs generates type declarations by default. Advanced customization requires forking or using #[ts(as=...)] / #[ts(type=...)] attributes for specific fields. The format feature enables basic prettification but does not change syntax structure.
What happens if a Rust type field is added/removed after bindings are generated?
Bindings must be regenerated (run cargo test or export API). CI/CD should validate that bindings are up-to-date; mismatches can cause runtime TypeScript errors. Version control bindings to detect drift.
Does ts-rs work with non-monorepo setups (separate frontend/backend repos)?
Yes, but requires additional CI/CD steps: generate bindings in backend, publish to npm/artifact repo, or include in API package. Monorepos simplify this with shared source control and single build pipeline.

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.