getFallbacksAsync

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.getFallbacksAsync<TSchema>(schema);

Generics

Parameters

  • schema TSchema

Returns

Examples

The following examples show how getFallbacksAsync can be used.

New user fallbacks

Get the fallback values of a new user schema.

import { getAnyUniqueUsername, isUsernameUnique } from '~/api';

const NewUserSchema = v.objectAsync({
  username: v.fallbackAsync(
    v.pipeAsync(v.string(), v.minLength(3), v.checkAsync(isUsernameUnique)),
    getAnyUniqueUsername
  ),
  password: v.pipe(v.string(), v.minLength(8)),
});

const fallbackValues = await v.getFallbacksAsync(NewUserSchema);
/*
  {
    username: "cookieMonster07",
    password: undefined
  }
*/

The following APIs can be combined with getFallbacksAsync.

Schemas

Methods

Async

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 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 caegdeveloper
  • GitHub profile picture of andrew-d-jackson
  • GitHub profile picture of dslatkin