omit

Creates an object schema that contains not the selected keys of an existing schema.

// Object schema with an optional pipe
const Schema = omit<TSchema, TKeys>(schema, keys, pipe);

// Object schema with an optional message and pipe
const Schema = omit<TSchema, TKeys>(schema, keys, message, pipe);

// Object schema with rest and optional pipe
const Schema = omit<TSchema, TKeys, TRest>(schema, keys, rest, pipe);

// Object schema with rest and optional message and pipe
const Schema = omit<TSchema, TKeys, TRest>(schema, keys, rest, message, pipe);

Generics

Parameters

  • schema TSchema
  • keys TKey
  • rest TRest
  • message ErrorMessage | undefined
  • pipe Pipe<ObjectOutput<Omit<TSchema['entries'], TKeys[number]>, TRest>> | undefined

Explanation

omit creates a new object schema that does not contain the selected keys of the given object schema. It is similar to TypeScript's Omit utility type.

Note that rest, message and pipe of the passed schema are completely ignored and must be added again.

Returns

  • Schema ObjectSchema<Omit<TSchema['entries'], TKeys[number]>, TRest>

Examples

The following examples show how omit can be used.

Omit specific keys

Schema that does not contain the selected keys of an existing schema.

const ObjectSchema = object({
  key1: string(),
  key2: number(),
  key3: boolean(),
});

const OmitSchema = omit(ObjectSchema, ['key1', 'key2']);

The following APIs can be combined with omit.

Schemas

Methods

Transformations

Validations

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of dailydotdev
  • GitHub profile picture of ivan-mihalic
  • GitHub profile picture of KATT
  • GitHub profile picture of osdiab
  • GitHub profile picture of Thanaen
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of caegdeveloper