getDefault
Returns the default value of the schema.
const value = v.getDefault<TSchema>(schema, dataset, config);
Generics
TSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
Parameters
schemaTSchemadatasetUnknownDataset | undefinedconfigConfig<InferIssue<TSchema>> | undefined
Returns
valueInferDefault<TSchema>
Examples
The following examples show how getDefault can be used.
Optional string schema
Get the default value of an optional string schema.
const OptionalStringSchema = v.optional(v.string(), "I'm the default!");
const defaultValue = v.getDefault(OptionalStringSchema); // "I'm the default!"
Related
The following APIs can be combined with getDefault.
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/getDefault/