title | description | source | contributors | |
---|---|---|---|---|
enum |
Creates an enum schema. |
/schemas/enum/enum.ts |
|
import { ApiList, Property } from '~/components'; import { properties } from './properties';
Creates an enum schema.
const Schema = v.enum<TEnum, TMessage>(enum, message);
TEnum
<Property {...properties.TEnum} />TMessage
<Property {...properties.TMessage} />
enum
{/* prettier-ignore */}<Property {...properties.enum} />message
<Property {...properties.message} />
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.
Schema
<Property {...properties.Schema} />
The following examples show how enum
can be used.
Schema to validate a direction enum option.
enum Direction {
Left,
Right,
}
const DirectionSchema = v.enum(Direction, 'Invalid direction');
The following APIs can be combined with enum
.
<ApiList items={[ 'array', 'intersect', 'lazy', 'looseObject', 'looseTuple', 'map', 'nonNullable', 'nonNullish', 'nonOptional', 'nullable', 'nullish', 'object', 'objectWithRest', 'optional', 'record', 'set', 'strictObject', 'strictTuple', 'tuple', 'tupleWithRest', 'union', ]} />
<ApiList items={[ 'fallback', 'getDefault', 'getDefaults', 'getFallback', 'getFallbacks', 'is', 'parse', 'pipe', 'safeParse', ]} />
<ApiList items={[ 'check', 'brand', 'rawCheck', 'rawTransform', 'readonly', 'transform', ]} />