x-to-zod / Builder
Interface: Builder<Z, T>
Defined in: src/Builder/index.ts:20
Builder — output contract for all schema parsers.
Extracted from the concrete ZodBuilder class so that:
- Parser return types are statically verifiable against the interface, not a class.
- Alternative output targets (AST, dry-run, Arktype) can be implemented without touching core parsing code.
- Custom parsers registered via
registerParser()are type-checked to return aBuilder, eliminating the untypedstringescape hatch.
All modifier methods return Builder (not this) to keep the interface simple and implementable by third parties. The concrete ZodBuilder class retains this return types for its own fluent chaining — TypeScript accepts this structural assignment.
Type Parameters
Z
Z extends ZodType = ZodType
T
T = Z extends ZodStringFormat ? Z["format"] : Z["type"]
Properties
typeKind
readonly typeKind: T;Defined in: src/Builder/index.ts:28
Parser type discriminator (e.g. 'string', 'object', 'anyOf'). Set by the parser that creates this builder.
Methods
brand()
brand(brand): this;Defined in: src/Builder/index.ts:58
Apply .brand(brand) modifier for nominal typing.
Parameters
brand
string
Brand string literal.
Returns
this
catch()
catch(value): this;Defined in: src/Builder/index.ts:67
Apply .catch(fallback) modifier for parse-failure recovery.
Parameters
value
unknown
Fallback value serialised as JSON in the generated code.
Returns
this
default()
default(value): this;Defined in: src/Builder/index.ts:46
Apply .default(value) modifier.
Parameters
value
unknown
Serialised as JSON in the generated code.
Returns
this
describe()
describe(description): this;Defined in: src/Builder/index.ts:52
Apply .describe(description) modifier.
Parameters
description
string
JSDoc description string.
Returns
this
meta()
meta(metadata): this;Defined in: src/Builder/index.ts:86
Apply .meta(obj) metadata (Zod v4+).
Parameters
metadata
Record<string, unknown>
Arbitrary key/value metadata object.
Returns
this
nullable()
nullable(): this;Defined in: src/Builder/index.ts:40
Apply .nullable() modifier to the generated schema.
Returns
this
optional()
optional(): this;Defined in: src/Builder/index.ts:37
Apply .optional() modifier to the generated schema.
Returns
this
readonly()
readonly(): this;Defined in: src/Builder/index.ts:61
Apply .readonly() modifier to the generated schema.
Returns
this
refine()
refine(refineFn, message?): this;Defined in: src/Builder/index.ts:74
Apply .refine(fn, message?) constraint.
Parameters
refineFn
string
Refine predicate as a code string (e.g. "(val) => val > 0").
message?
string
Optional error message string.
Returns
this
superRefine()
superRefine(superRefineFn): this;Defined in: src/Builder/index.ts:80
Apply .superRefine(fn) constraint.
Parameters
superRefineFn
string
SuperRefine function as a code string.
Returns
this
text()
text(): string;Defined in: src/Builder/index.ts:34
Emit the final Zod expression as a TypeScript code string. Example: z.string().optional().describe("name")
Returns
string
transform()
transform(transformFn): this;Defined in: src/Builder/index.ts:92
Apply .transform(fn) mapping.
Parameters
transformFn
string
Transform function as a code string.
Returns
this