I have an enum defined as following:
export enum SwitchEnum{
On = 'ON',
Off = 'OFF',
}
I want to create a an array of objects from this enum so I tried as following:
export interface SelectProps {
id: number;
value: string | number | undefined;
label: string | undefined;
}
const listItems: SelectProps [] = Object.keys(SwitchEnum).map((key, index) => ({
id: index,
value: SwitchEnum[key],
label: key
}));
But Typescript is complaining with this error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof SwitchEnum'.
No index signature with a parameter of type 'string' was found on type 'typeof SwitchEnum'
How can I solve this?