Spec-Zone.ru › Valibot

nonNullish

Creates a non nullish schema.

This schema function can be used to override the behavior of nullish.

const Schema = v.nonNullish<TWrapped, TMessage>(wrapped, message);

Generics

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

Parameters

  • wrapped TWrapped
  • message TMessage

Explanation

With nonNullish 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 NonNullishSchema<TWrapped, TMessage>

Examples

The following examples show how nonNullish can be used.

Non nullish string

Schema that does not accept null and undefined.

const NonNullishStringSchema = v.nonNullish(v.nullish(v.string()));

Unwrap non nullish

Use unwrap to undo the effect of nonNullish.

const NonNullishNumberSchema = v.nonNullish(v.nullish(v.number()));
const NullishNumberSchema = v.unwrap(NonNullishNumberSchema);

Related

The following APIs can be combined with nonNullish.

Schemas

any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, 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/nonNullish/

Spec-Zone.ru

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