A better way to define enums
in Typescript
const ORDER_STATUS = { OPEN: 'Offen', ORDERED: 'Bestellt', CANCELED: 'Storniert' } as const; type OrderStatus = keyof typeof ORDER_STATUS; function methodWithEnum(status: OrderStatus) { console.info(`${ORDER_STATUS[status]}: ${status}`); } methodWithEnum("OPEN");
In this way it is much easier to provide an enum
including a potential mapping to a different value e.g. a display value.
This solution is usually considered being better, as long as enums
aren’t supported by JavaScript natively.