nonNullishAsync
Creates a non nullish schema.
This schema function can be used to override the behavior of
nullishAsync.
const Schema = v.nonNullishAsync<TWrapped, TMessage>(wrapped, message);
Generics
TWrappedextends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>TMessageextends ErrorMessage<NonNullishIssue> | undefined
Parameters
wrappedTWrappedmessageTMessage
Explanation
With nonNullishAsync the validation of your schema will not pass null and undefined inputs. If the input is null or undefined, you can use message to customize the error message.
Returns
SchemaNonNullishSchemaAsync<TWrapped, TMessage>
Examples
The following examples show how nonNullishAsync can be used.
Allowed country schema
Schema to check if a string matches one of the allowed country names.
import { isAllowedCountry } from '~/api';
const AllowedCountrySchema = v.nonNullishAsync(
// Assume this schema is from a different file and reused here.
v.nullishAsync(
v.pipeAsync(v.string(), v.nonEmpty(), v.checkAsync(isAllowedCountry))
)
);
Related
The following APIs can be combined with nonNullishAsync.
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, nonNullableAsync, 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/nonNullishAsync/