getFallbacks

Returns the fallback values of the schema.

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

const values = 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 = object({ key: fallback(string(), "I'm the fallback!") });
const fallbackValues = getFallbacks(ObjectSchema); // { key: "I'm the fallback!" }

Tuple fallbacks

Get the fallback values of a tuple schema.

const TupleSchema = tuple([fallback(number(), 100)]);
const fallbackValues = 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

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