enum
Creates an enum schema.
const Schema = v.enum<TEnum, TMessage>(enum, message);
Generics
TEnumextends EnumTMessageextends ErrorMessage<EnumIssue> | undefined
Parameters
enumTEnummessageTMessage
Explanation
With enum you can validate that the input corresponds to an enum option. If the input is invalid, you can use message to customize the error message.
Returns
SchemaEnumSchema<TEnum, TMessage>
Examples
The following examples show how enum can be used.
Direction enum
Schema to validate a direction enum option.
enum Direction {
Left,
Right,
}
const DirectionSchema = v.enum(Direction, 'Invalid direction');
Related
The following APIs can be combined with enum.
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, guard, metadata, rawCheck, rawTransform, readonly, title, transform
Utils
entriesFromList, isOfKind, isOfType
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/enum/