nonNullableAsync
Creates a non nullable schema.
This schema function can be used to override the behavior of
nullableAsync.
const Schema = v.nonNullableAsync<TWrapped, TMessage>(wrapped, message);
Generics
TWrappedextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>TMessageextends ErrorMessage<NonNullableIssue> | undefined
Parameters
wrappedTWrappedmessageTMessage
Explanation
With nonNullableAsync 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
SchemaNonNullableSchemaAsync<TWrapped, TMessage>
Examples
The following examples show how nonNullableAsync can be used.
Unique username schema
Schema to validate a non-null unique username.
import { isUsernameUnique } from '~/api';
const UniqueUsernameSchema = v.nonNullableAsync(
// Assume this schema is from a different file and reused here.
v.nullableAsync(
v.pipeAsync(
v.string(),
v.nonEmpty(),
v.checkAsync(isUsernameUnique, 'The username is not unique.')
)
)
);
Related
The following APIs can be combined with nonNullableAsync.
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
config, getDefault, getFallback, unwrap
Actions
brand, check, description, flavor, guard, metadata, partialCheck, rawCheck, rawTransform, readonly, title, transform
Utils
entriesFromList, isOfKind, isOfType
Async
arrayAsync, awaitAsync, checkAsync, customAsync, exactOptionalAsync, fallbackAsync, getDefaultsAsync, getFallbacksAsync, intersectAsync, lazyAsync, looseObjectAsync, looseTupleAsync, mapAsync, nonNullishAsync, nonOptionalAsync, nullableAsync, nullishAsync, objectAsync, objectWithRestAsync, optionalAsync, parseAsync, parserAsync, partialCheckAsync, pipeAsync, rawCheckAsync, rawTransformAsync, recordAsync, safeParseAsync, safeParserAsync, setAsync, strictObjectAsync, strictTupleAsync, transformAsync, tupleAsync, tupleWithRestAsync, unionAsync, variantAsync
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/nonNullableAsync/