TypeScript


Glue supports typescript as a code generation target.

Simply run:

shell

#Output modes

TypeScript generation supports:

  • Types only (default): emits export type ...
  • Zod mode: emits Zod schemas and inferred types

Enable Zod mode in .gluerc:

yaml

#Example

For this Glue spec:

glue

...generating TypeScript...

shell

...will produce code similar to:

ts

With typescript.zod: true, output is schema-first:

ts

#Notes

  • Nested Glue models are emitted as flattened names (e.g. Parent_Child).
  • All integer primitives emit number (or z.number() in Zod mode).
  • Record<K, V> is emitted as Record<K, V> (or z.record(...) in Zod mode).
  • Tuples are emitted as TypeScript tuple types, e.g. [string, number] (or z.tuple(...) in Zod mode).
  • Glue type aliases are emitted as exported TypeScript type aliases. Aliases starting with _ are inlined instead.
  • Anonymous structs are emitted inline in both types-only and Zod output.