typescript string as enum code example
Example 1: typescript string to enum
enum Day {
BeforeNoon = "AM",
AfterNoon = "PM"
}
var beforeNoon : string = "AM";
var enumValue : Day = (<any>Day)[beforeNoon];
Example 2: typescript enum value to enum
enum Number {
One,
Two
}
const numberOne: Number = "One" as Number;
const otherNumberOne: Number = Number.One;
const stringOne = Number[Number.One];