Skip to main content

Module typescript

Module typescript 

Source
Expand description

TypeScript model generation.

Emits a models.ts of plain interfaces, one export interface per model and one export type string-literal union per string union.

§Why interfaces rather than classes

Generated code inherits its shape onto every consumer. A schema describing a file format (the motivating case is a DAW project document) wants to describe the JSON it reads without pulling a runtime in first. Interfaces are erased at compile time, so the output is pure type information with no runtime cost and no dependency.

The cost is that this validates nothing beyond shape: an out-of-range value that the JSON Schema would reject still type-checks. Constraints in the IR are emitted as comments so they are visible, not enforced.

Functions§

generate
Generate TypeScript models for a schema.