how to use enum in typescript 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 type from enum values

enum Weekday {
  MONDAY = 'mon',
  TUESDAY = 'tue',
  WEDNESDAY = 'wed'
}

type WeekdayType = `${Weekday}`;

Example 3: ts enum definition

enum PrintMedia {
  Newspaper,
  Newsletter,
  Magazine,
  Book
}

Example 4: enum in ts

enum Direction {
    Up,
    Down,
    Left,
    Right,
}

Example 5: enums in typescript

enum Direction {
  Up = 1,
  Down,
  Left,
  Right,
}