Spec-Zone.ru › Valibot

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

  • TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>
  • TMessage extends ErrorMessage<NonNullishIssue> | undefined

Parameters

  • wrapped TWrapped
  • message TMessage

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

  • Schema NonNullishSchemaAsync<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/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API