partial

Creates an object schema consisting of all properties of an existing object schema set to optional.

// Partial object schema with an optional pipe
const Schema = partial<TSchema>(schema, pipe);

// Partial object schema with an optional message and pipe
const Schema = partial<TSchema>(schema, message, pipe);

// Partial object schema with rest and optional pipe
const Schema = partial<TSchema, TRest>(schema, rest, pipe);

// Partial object schema with rest and optional message and pipe
const Schema = partial<TSchema, TRest>(schema, rest, message, pipe);

Generics

Parameters

Explanation

partial creates a new object schema where the entries of the provided object schema are optional. It is similar to TypeScript's Partial utility type.

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

Returns

Examples

The following examples show how partial can be used.

Partial object schema

Schema to validate an object with partial entries.

const PartialObjectSchema = partial(
  object({
    key1: string(),
    key2: number(),
  })
);

The following APIs can be combined with partial.

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 hyunbinseo
  • GitHub profile picture of caegdeveloper