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.
Inheriting the parent's options, or not
Loading playground…
Removing parent fields
Loading playground…