Interface EnumFieldDef

A schema field definition for an enum type.

The values tuple defines the allowed string literals, used for both TypeScript type inference (values[number] → string literal union) and Zod runtime validation (z.enum(values)).

Enum fields can appear at any nesting level: top-level, inside nested objects, or as array items.

const schema = {
// Top-level enum
status: { type: "enum", values: ["active", "inactive"] },

// Nullable enum
category: { type: "enum", values: ["home", "work", "other"], nullable: true },

// Enum inside a nested object
geo: {
type: "object",
fields: {
accuracy: { type: "enum", values: ["precise", "approximate"] }
}
},

// Array of enum values
roles: { type: "array", items: { type: "enum", values: ["admin", "user", "guest"] } }
} as const satisfies ObjectSchema;

type T = InferObjectSchema<typeof schema>;
// {
// status: "active" | "inactive";
// category?: "home" | "work" | "other" | null;
// geo: { accuracy: "precise" | "approximate" };
// roles: ("admin" | "user" | "guest")[];
// }
interface EnumFieldDef {
    nullable?: boolean;
    type: "enum";
    values: readonly [string, string];
}

Properties

Properties

nullable?: boolean

When true, the field accepts null and becomes optional.

type: "enum"

Must be "enum" to indicate an enum field.

values: readonly [string, string]

A non-empty readonly tuple of allowed string values.

At the type level, values[number] produces the union of allowed string literals. At runtime, this is passed to z.enum() for validation.

Must contain at least one value (enforced by the [string, ...string[]] tuple type).