Skip to content

Function: Enum() ​

ts
function 
Enum
<
T
>(...
values
):
TypeFunction
<
T
>;

Defined in: packages/advanced-types/src/index.ts:23

Creates a Enum type function that validates the input against allowed values. The display name will be formatted as "value1 | value2 | ..." for help output.

Type Parameters ​

Type Parameter

T extends string

Parameters ​

ParameterTypeDescription

...values

T[]

Array of allowed string values

Returns ​

TypeFunction<T>

A TypeFunction that validates and returns the input value

Example ​

typescript
const 
format
= Enum(["json", "yaml", "xml"]);
// Help output will show: json | yaml | xml

Throws ​

If the value is not in the allowed values list

在 MIT 许可证下发布