Skip to main content
Version: 2.0.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.OptionsAny 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.
const StrictAdminSchema = UserSchema.extend<AdminInput, Admin>(
(b) => b.field(b.required("role").allow(["admin"])),
{ useParentOptions: false, timestamps: false },
);