ts-gen
Generate wasm-bindgen Rust bindings from TypeScript .d.ts declaration files.
Overview
ts-gen reads TypeScript .d.ts files and produces Rust source code containing #[wasm_bindgen] extern blocks, ready to compile against wasm-bindgen.
Pipeline
.d.ts files
-> oxc_parser (AST)
-> First Pass phase 1: collect all type names into TypeRegistry
-> First Pass phase 2: populate full IR (resolve references, merge var+interface patterns)
-> Assembly: group by ModuleContext, resolve inheritance chains, classify types
-> Code Generation: IR -> syn::File -> prettyplease -> .rs files
Installation
CLI
Library
The cli feature (enabled by default) pulls in clap and walkdir for the
binary. Disable it if you only need the library API.
Usage
CLI
Process a directory of declaration files:
Map external types from other crates:
Library API
use ;
let source = r#"
export declare class Greeter {
constructor(name: string);
greet(): string;
}
"#;
let = parse_source?;
let rust_code = generate?;
println!;
Supported TypeScript constructs
- Classes (including abstract classes and inheritance)
- Interfaces (classified as class-like or dictionary types)
- Functions and variables
- String and numeric enums
- Type aliases
- Namespaces
- Module declarations
- Generics (partial -- type parameters are erased to their base types)
Known limitations
- Generic type arguments are not yet preserved in codegen; generic types
emit their base name only. This will improve as
wasm-bindgengeneric support matures. - The parsed IR uses
Rc<str>internally and is!Send/!Sync.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.