Skip to content

langium-zod / ZodTypeExpression

Type Alias: ZodTypeExpression

ts
type ZodTypeExpression = 
  | {
  kind: "primitive";
  primitive: ZodPrimitive;
}
  | {
  kind: "literal";
  value: string;
}
  | {
  kind: "reference";
  typeName: string;
}
  | {
  element: ZodTypeExpression;
  kind: "array";
}
  | {
  kind: "crossReference";
  targetType: string;
}
  | {
  kind: "union";
  members: ZodTypeExpression[];
}
  | {
  inner: ZodTypeExpression;
  kind: "lazy";
};

Defined in: types.ts:28

A discriminated union that represents a single Zod type node in the descriptor tree produced by the extractor and consumed by the code generator.

Each variant maps to a specific Zod combinator:

  • primitivez.string() / z.number() / z.boolean() / z.bigint()
  • literalz.literal(value)
  • reference<TypeName>Schema (a reference to another generated schema)
  • arrayz.array(element)
  • crossReferenceReferenceSchema (Langium cross-reference, optionally refined with zRef when cross-reference validation is enabled)
  • unionz.union([...members])
  • lazyz.lazy(() => inner) (used for self-referential types)

Remarks

This type is part of the lower-level descriptor API. Most consumers do not need to construct ZodTypeExpression values directly; they are produced by the extractor from Langium grammar types. Custom descriptor transformations (e.g. injecting additional validation constraints before code generation) are the primary use case.

See

Released under the MIT License.