Skip to content

Function.oneOf

github-actions[bot] edited this page Jun 9, 2026 · 32 revisions

umt / oneOf

Function: oneOf()

oneOf<T>(values, message?): (value) => OneOfReturnType<T[number]>

Defined in: Validate/string/oneOf.ts:38

Creates a top-level validator that checks if a string value is one of the given allowed literal values. The literal union is captured via const T and exposed through the OneOfReturnType<T[number]> return type.

Type Parameters

T

T extends readonly string[]

The tuple of allowed string literals

Parameters

values

T

The tuple of allowed string values

message?

string

Custom error message for validation failure

Returns

A validator function from string to OneOfReturnType<T[number]>

(value) => OneOfReturnType<T[number]>

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally