boolean
Creates a boolean schema.
const Schema = v.boolean<TMessage>(message);
Generics
TMessageextends ErrorMessage<BooleanIssue> | undefined
Parameters
messageTMessage
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
pipeto forcetrueorfalseas a value, in most cases it makes more sense to useliteralfor better typing.
Returns
SchemaBooleanSchema<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/