typescript string to enum code example
Example 1: typescript enum to string
enum AnEnum {
One = 1,
Two = 2
}
let stringOne = AnEnum[1]; // "One"
let stringTwo = AnEnum[AnEnum.Two]; // "Two"
Example 2: typescript string to enum
enum Day {
BeforeNoon = "AM",
AfterNoon = "PM"
}
var beforeNoon : string = "AM";
var enumValue : Day = (Day)[beforeNoon];
Example 3: enum in ts
enum Direction {
Up,
Down,
Left,
Right,
}