Skip to content

Latest commit

History

History
114 lines (88 loc) 路 1.75 KB

index.mdx

File metadata and controls

114 lines (88 loc) 路 1.75 KB
title description source contributors
enum
Creates an enum schema.
/schemas/enum/enum.ts
fabian-hiller

import { ApiList, Property } from '~/components'; import { properties } from './properties';

enum

Creates an enum schema.

const Schema = v.enum<TEnum, TMessage>(enum, message);

Generics

  • TEnum <Property {...properties.TEnum} />
  • TMessage <Property {...properties.TMessage} />

Parameters

  • enum {/* prettier-ignore */}<Property {...properties.enum} />
  • message <Property {...properties.message} />

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

  • Schema <Property {...properties.Schema} />

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

<ApiList items={[ 'array', 'intersect', 'lazy', 'looseObject', 'looseTuple', 'map', 'nonNullable', 'nonNullish', 'nonOptional', 'nullable', 'nullish', 'object', 'objectWithRest', 'optional', 'record', 'set', 'strictObject', 'strictTuple', 'tuple', 'tupleWithRest', 'union', ]} />

Methods

<ApiList items={[ 'fallback', 'getDefault', 'getDefaults', 'getFallback', 'getFallbacks', 'is', 'parse', 'pipe', 'safeParse', ]} />

Actions

<ApiList items={[ 'check', 'brand', 'rawCheck', 'rawTransform', 'readonly', 'transform', ]} />