Skip to main content
Version: 2.2.0

Extending Schemas

Use .extend() to create a new schema that inherits fields from an existing one.

Loading playground…

Options​

OptionTypeDefaultDescription
useParentOptionsbooleantrueInherit equalityDepth, sanitizeError, and timestamps.
removestring | 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.
  • remove deletes fields after copying.
  • Only equalityDepth, sanitizeError, and timestamps are inherited when useParentOptions is true. Set it to false to start from the options passed to extend() only.

Inheriting the parent's options, or not​

Loading playground…

Removing parent fields​

Loading playground…