I'm trying to convert enum value strings to actual enums. I know you can just compare a string and be done with it (e.g. MyEnum.FirstEnum === 'My_First_Enum' would return true), but it would be nice if I can return enums instead of strings.
export enum MyEnum {
FirstEnum = 'My_First_Enum',
SecondEnum = 'My_Second_Enum',
ThirdEnum = 'My_Third_Enum'
}
getMyEnums(): MyEnum[] {
// These would be an input argument, but for the sake of this example, I thought this was easier to understand
const stringEnumValues = ['My_Second_Enum', 'My_Third_Enum'];
// Convert to enums (result is [undefined, undefined])
return stringEnumValues.map(e => MyEnum[e]);
}