nonNullable
Creates a non nullable schema.
This schema function can be used to override the behavior of
nullable.
const Schema = v.nonNullable<TWrapped, TMessage>(wrapped, message);
Generics
TWrappedextends BaseSchema<unknown, unknown, BaseIssue<unknown>>TMessageextends ErrorMessage<NonNullableIssue> | undefined
Parameters
wrappedTWrappedmessageTMessage
Explanation
With nonNullable the validation of your schema will not pass null inputs. If the input is null, you can use message to customize the error message.
Returns
SchemaNonNullableSchema<TWrapped, TMessage>
Examples
The following examples show how nonNullable can be used.
Non nullable string
Schema that does not accept null.
const NonNullableStringSchema = v.nonNullable(v.nullable(v.string()));
Unwrap non nullable
Use unwrap to undo the effect of nonNullable.
const NonNullableNumberSchema = v.nonNullable(v.nullable(v.number()));
const NullableNumberSchema = v.unwrap(NonNullableNumberSchema);
Related
The following APIs can be combined with nonNullable.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, 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, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser, unwrap
Actions
check, brand, description, flavor, guard, metadata, partialCheck, rawCheck, rawTransform, readonly, title, transform
Utils
entriesFromList, isOfKind, isOfType
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/nonNullable/