I have an enum:
export enum ApiMessages {
logged_ok = \'Logged OK\',
register_ok = \'Register OK\'
}
I have a function with the enu
For those who come looking as I did, this works for me.
NOTE: This is only valid if you know that your string value is a valid 'key'.
enum Fruit {
Apple = 'apple',
Bananna = 'bananna'
}
const str: string = 'apple';
const fruit = str as Fruit;
if (fruit === Fruit.Apple)
console.log("It's an apple");
if (fruit === Fruit.Bananna)
console.log("It's a bananna");