getFallbacksAsync
Returns the fallback values of the schema.
The difference to
getFallbackis that for object and tuple schemas this function recursively returns the fallback values of the subschemas instead ofundefined.
const values = v.getFallbacksAsync<TSchema>(schema);
Generics
TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
Parameters
schemaTSchema
Returns
valuesPromise<InferFallbacks<TSchema>>
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
}
*/
Related
The following APIs can be combined with getFallbacksAsync.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void
Methods
assert, config, fallback, keyof, message, omit, partial, pick, pipe, required, unwrap
Async
arrayAsync, customAsync, exactOptionalAsync, fallbackAsync, intersectAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullableAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, partialAsync, pipeAsync, recordAsync, requiredAsync, setAsync, strictObjectAsync, strictTupleAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/getFallbacksAsync/