I have the following enum object in TypeScript:
enum ClassesTypes {
READY = 'ready',
DELETED = 'deleted',
}
How can I get from it the following array? ['ready', 'deleted']
?
- Tried to use the following code:
const arr = Object.keys(ClassesTypes).map(key => ClassesTypes[key]);
But get the following error:
TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.>
- When I tried to change it to the following according to this answer
const arr = Object.keys(ClassesTypes).map((key: keyof typeof ClassesTypes) => ClassesTypes[key]);
I get the following error:
TS2345: Argument of type '(key: "READY" | "DELETED") => ClassesTypes' is not assignable to parameter of type '(value: string, index: number, array: string[]) => ClassesTypes'. Types of parameters 'key' and 'value' are incompatible. Type 'string' is not assignable to type '"READY" | "DELETED"'