getFallbacks

Returns the fallback values of the schema.

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

const values = v.getFallbacks<TSchema>(schema);

Generics

Parameters

  • schema TSchema

Returns

Examples

The following examples show how getFallbacks can be used.

Object fallbacks

Get the fallback values of an object schema.

const ObjectSchema = v.object({
  key: v.fallback(v.string(), "I'm the fallback!"),
});

const fallbackValues = v.getFallbacks(ObjectSchema); // { key: "I'm the fallback!" }

Tuple fallbacks

Get the fallback values of a tuple schema.

const TupleSchema = v.tuple([v.fallback(v.number(), 100)]);
const fallbackValues = v.getFallbacks(TupleSchema); // [100]

The following APIs can be combined with getFallbacks.

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 isoden
  • GitHub profile picture of nickytonline
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of luckasnix
  • GitHub profile picture of andrew-3kb
  • GitHub profile picture of dslatkin