Skip to main content

Function: enumToObject()

enumToObject<T>(enumObject: T): { [K in Exclude<keyof T, `${number}`>]: T[K] }

Converts a TypeScript enum to a 1-way object, stripping out the number keys.

Type parameters

Type parameter
T extends object

Parameters

ParameterTypeDescription
enumObjectTThe enum to convert

Returns

{ [K in Exclude<keyof T, `${number}`>]: T[K] }

The mapped object

Example

enum Permissions {
Read: 1 << 0,
Write: 1 << 1
}
// {
// Read: 1,
// Write: 2,
// 1: 'Read',
// 2: 'Write'
// }

enumToObject(Permissions);
// { Read: 1, Write: 2 }

Source

lib/utilities.ts:22