Skip to content

Enums ​

Enums: listing members, checking and reading untyped values, literal types.

ExportWhat it does
EnumLiteralTurns 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.
EnumObjectAny TypeScript enum, or a const object used as one.
getEnumEntriesLists the members of an enum as [name, value] pairs, without the reverse mapping of numeric enums.
getEnumKeyFinds the member name of an enum value, string enums included: a readable name for a log or a translation key.
getEnumKeysLists the member names of an enum, without the reverse mapping of numeric enums.
getEnumValuesLists the values of an enum, without the names of the reverse mapping of numeric enums.
isEnumValueChecks whether a value is one of the values of an enum, in O(1): the values of each enum are read once.
parseEnumValueReads an enum member from a text, such as a query parameter: '1' gives the member of value 1.
toEnumValueReturns a value typed as an enum member: the value itself when it belongs to the enum, the fallback otherwise.

Generated from the JSDoc of the sources.