Is there a way to convert enum value strings to actual enums in TypeScript? While it's possible to compare strings directly (e.g. MyEnum.FirstEnum === 'My_First_Enum' would return true), I'm interested in finding a method to return enums instead of strings.
export enum MyEnum {
FirstEnum = 'My_First_Enum',
SecondEnum = 'My_Second_Enum',
ThirdEnum = 'My_Third_Enum'
}
getMyEnums(): MyEnum[] {
// These would typically be input arguments, but for this example simplicity sake, I provided them here
const stringEnumValues = ['My_Second_Enum', 'My_Third_Enum'];
// Convert to enums (result will currently be [undefined, undefined])
return stringEnumValues.map(e => MyEnum[e]);
}