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
Parameter | Type | Description |
---|---|---|
enumObject | T | The 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 }