required

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

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

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

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

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

Generics

Parameters

Explanation

required creates a new object schema where the entries of the provided object schema are non optional. It is similar to TypeScript's Required 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 required can be used.

Required object schema

Schema to validate an object with required entries.

const RequiredObjectSchema = required(
  object({
    key1: optional(string()),
    key2: optional(number()),
  })
);

The following APIs can be combined with required.

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