Spec-Zone.ru › Valibot

boolean

Creates a boolean schema.

const Schema = v.boolean<TMessage>(message);

Generics

  • TMessage extends ErrorMessage<BooleanIssue> | undefined

Parameters

  • message TMessage

Explanation

With boolean you can validate the data type of the input. If the input is not a boolean, you can use message to customize the error message.

Instead of using a pipe to force true or false as a value, in most cases it makes more sense to use literal for better typing.

Returns

  • Schema BooleanSchema<TMessage>

Examples

The following examples show how boolean can be used.

Custom message

Boolean schema with a custom error message.

const BooleanSchema = v.boolean('A boolean is required');

Related

The following APIs can be combined with boolean.

Schemas

array, exactOptional, intersect, lazy, looseObject, looseTuple, map, nonNullable, nonNullish, nonOptional, nullable, nullish, object, objectWithRest, optional, record, set, strictObject, strictTuple, tuple, tupleWithRest, undefinedable, union

Methods

assert, config, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser

Actions

check, brand, description, flavor, gtValue, guard, ltValue, maxValue, maxWords, metadata, minValue, notValue, notValues, rawCheck, rawTransform, readonly, title, toMaxValue, toMinValue, transform, value, values

Utils

entriesFromList, isOfKind, isOfType

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/boolean/

Spec-Zone.ru

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