typescript value from enum code example
Example 1: typescript enum to string
enum AnEnum {
One = 1,
Two = 2
}
let stringOne = AnEnum[1];
let stringTwo = AnEnum[AnEnum.Two];
Example 2: typescript type from enum values
enum Weekday {
MONDAY = 'mon',
TUESDAY = 'tue',
WEDNESDAY = 'wed'
}
type WeekdayType = `${Weekday}`;
Example 3: declare enum in type script
enum PrintMedia {
Newspaper = 1,
Newsletter,
Magazine,
Book
}
Example 4: 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];