Enums
Enums: listing members, checking and reading untyped values, literal types.
| Export | What it does |
|---|---|
EnumLiteral | Turns an enum type into the union of its literal values, so plain literals are accepted where the enum is expected: 'idle' | 'running' for a string enum, 0 | 1 for a numeric one. |
EnumObject | Any TypeScript enum, or a const object used as one. |
getEnumEntries | Lists the members of an enum as [name, value] pairs, without the reverse mapping of numeric enums. |
getEnumKey | Finds the member name of an enum value, string enums included: a readable name for a log or a translation key. |
getEnumKeys | Lists the member names of an enum, without the reverse mapping of numeric enums. |
getEnumValues | Lists the values of an enum, without the names of the reverse mapping of numeric enums. |
isEnumValue | Checks whether a value is one of the values of an enum, in O(1): the values of each enum are read once. |
parseEnumValue | Reads an enum member from a text, such as a query parameter: '1' gives the member of value 1. |
toEnumValue | Returns a value typed as an enum member: the value itself when it belongs to the enum, the fallback otherwise. |