getFallback
Returns the fallback value of the schema.
const value = v.getFallback<TSchema>(schema, dataset, config);
Generics
TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
Parameters
schemaTSchemadatasetOutputDataset<InferOutput<TSchema>, InferIssue<TSchema>> | undefinedconfigConfig<InferIssue<TSchema>> | undefined
Returns
valueInferFallback<TSchema>
Examples
The following examples show how getFallback can be used.
Fallback string schema
Get the fallback value of a string schema.
const FallbackStringSchema = v.fallback(v.string(), "I'm the fallback!");
const fallbackValue = v.getFallback(FallbackStringSchema); // "I'm the fallback!"
Related
The following APIs can be combined with getFallback.
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/getFallback/