5 unstable releases
Uses new Rust 2024
| 0.43.2 | Jan 23, 2026 |
|---|---|
| 0.43.1 | Jan 23, 2026 |
| 0.43.0 | Jan 22, 2026 |
| 0.42.0 | Jan 6, 2026 |
| 0.41.0 | Dec 31, 2025 |
#2395 in Encoding
83 downloads per month
1MB
20K
SLoC
facet-typescript
facet-typescript
Generate TypeScript type definitions from facet type metadata.
This crate uses facet's reflection capabilities to generate TypeScript interfaces
and types from any type that implements Facet. Unlike going through JSON Schema,
this generates TypeScript directly, preserving:
- Exact optional field semantics
- Union types for enums
- Literal types for discriminated unions
- Proper
readonlymodifiers
Usage
use facet::Facet;
use facet_typescript::to_typescript;
#[derive(Facet)]
struct User {
name: String,
age: u32,
email: Option<String>,
}
let ts = to_typescript::<User>();
println!("{}", ts);
Output
export interface User {
name: string;
age: number;
email?: string;
}
Multiple Types
Generate types for multiple related types at once:
use facet_typescript::TypeScriptGenerator;
let mut gen = TypeScriptGenerator::new();
gen.add_type::<User>();
gen.add_type::<Post>();
gen.add_type::<Comment>();
let ts = gen.finish();
Sponsors
Thanks to all individual sponsors:
...along with corporate sponsors:
...without whom this work could not exist.
Special thanks
The facet logo was drawn by Misiasart.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.