How to check if a given string key exists in Enum?
enums, typescript
Solution
You could use the `in` operator:
if ('value4' in someEnum) {
// ...
}
Problem
I have an enum defined like this: ``` export enum someEnum { None = <any>'', value1 = <any>'value1', value2 = <any>'value2', value3 = <any>'value3' } ``` For example, I want to check "value4" key exists in an enum. I should get `false` as value4 is not defined on the enum. I tried `if (someEnum['value4'])` but got an error: Element implicitly has an 'any' type because index expression is not of type 'number'.