getDefaults

Returns the default values of the schema.

The difference to getDefault is that for object and tuple schemas this function recursively returns the default values of the subschemas instead of undefined.

const values = v.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 = v.object({
  key: v.optional(v.string(), "I'm the default!"),
});

const defaultValues = v.getDefaults(ObjectSchema); // { key: "I'm the default!" }

Tuple defaults

Get the default values of a tuple schema.

const TupleSchema = v.tuple([v.nullable(v.number(), 100)]);
const defaultValues = v.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
  • GitHub profile picture of EltonLobo07

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 antfu
  • GitHub profile picture of Thanaen
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of fabulousgk
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of nickytonline
  • GitHub profile picture of KubaJastrz
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of luckasnix
  • GitHub profile picture of andrew-3kb
  • GitHub profile picture of dslatkin