facet-typescript

Crates.iofacet-typescript
lib.rsfacet-typescript
version0.43.2
created_at2025-12-31 12:33:40.482421+00
updated_at2026-01-23 18:06:31.665878+00
descriptionGenerate TypeScript type definitions from facet type metadata
homepagehttps://facet.rs
repositoryhttps://github.com/facet-rs/facet
max_upload_size
id2014616
size67,426
Amos Wenger (fasterthanlime)

documentation

README

facet-typescript

Coverage Status crates.io documentation MIT/Apache-2.0 licensed Discord

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 readonly modifiers

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:

GitHub Sponsors Patreon

...along with corporate sponsors:

AWS Zed Depot

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.

Commit count: 3380

cargo fmt