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;
use to_typescript;
let ts = ;
println!;
Output
export interface User {
name: string;
age: number;
email?: string;
}
Multiple Types
Generate types for multiple related types at once:
use TypeScriptGenerator;
let mut gen = new;
gen.;
gen.;
gen.;
let ts = gen.finish;
LLM contribution policy
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.