Skip to content

Function.literal

github-actions[bot] edited this page Nov 18, 2026 · 13 revisions

umt / literal

Function: literal()

literal<T>(expected, message?): ((value) => LiteralResult<T>) & StandardSchemaV1<T, T>

Defined in: Validate/literal/core.ts:36

Creates a validator that accepts exactly one primitive value. The value is compared with strict equality (===), so literal(NaN) never matches and literal(0) matches -0. String literals are carried through the type field as a LiteralBrand so they are not confused with reserved type tags such as "string" when composed inside object(), union(), or arrayOf().

Type Parameters

T

T extends LiteralValue

The literal value accepted by the validator

Parameters

expected

T

The only value accepted by the validator

message?

string = ""

Custom error message for validation failure

Returns

((value) => LiteralResult<T>) & StandardSchemaV1<T, T>

  • Validator function that checks if the value is strictly equal to expected

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally