getFallbacks
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.getFallbacks<TSchema>(schema);
Generics
TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>>
Parameters
schemaTSchema
Returns
valuesInferFallbacks<TSchema>
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]
Related
The following APIs can be combined with getFallbacks.
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
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/getFallbacks/