getDefaults

Returns the default values of the schema.

The difference to getDefault is that for objects and tuples without an explicit default value, this function recursively returns the default values of the subschemas instead of undefined.

const values = getDefaults<TSchema>(schema);

Generics

Parameters

  • schema TSchema

Returns

Examples

The following examples show how getDefaults can be used.

Object defaults

Get the default values of an object schema.

const ObjectSchema = object({ key: optional(string(), "I'm the default!") });
const defaultValues = getDefaults(ObjectSchema); // { key: "I'm the default!" }

Tuple defaults

Get the default values of a tuple schema.

const TupleSchema = tuple([nullable(number(), 100)]);
const defaultValues = getDefaults(TupleSchema); // [100]

The following APIs can be combined with getDefaults.

Schemas

Methods

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