Extending Schemas
Use .extend() to create a new schema that inherits fields from an existing one.
Loading playground…
Options
| Option | Type | Default | Description |
|---|---|---|---|
useParentOptions | boolean | true | Inherit equalityDepth, sanitizeError, and timestamps. |
remove | string | string[] | [] | Field names to drop from the parent schema. |
| ... | NS.Options | — | Any other schema option can be provided and will override inheritance. |
Inheritance rules
- Parent definitions are copied first, then the extension builder is applied.
- Re-declaring a parent field name overwrites the parent definition.
removedeletes fields after copying.- Only
equalityDepth,sanitizeError, andtimestampsare inherited whenuseParentOptionsistrue. Set it tofalseto start from the options passed toextend()only.
const StrictAdminSchema = UserSchema.extend<AdminInput, Admin>(
(b) => b.field(b.required("role").allow(["admin"])),
{ useParentOptions: false, timestamps: false },
);