typescript enum type code example

Example 1: .env typescript

npm install dotenv;
 OR 
yarn add dotenv;


import * as dotenv from 'dotenv';

//inside your starter code, do this
...
...
dotenv.config();
...

Example 2: typescript enum to string

enum AnEnum {
    One = 1,
    Two = 2
}
let stringOne = AnEnum[1]; // "One"
let stringTwo = AnEnum[AnEnum.Two]; // "Two"

Example 3: typescript type from enum values

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

type WeekdayType = `${Weekday}`;

Example 4: ts enum definition

enum PrintMedia {
  Newspaper,
  Newsletter,
  Magazine,
  Book
}

Example 5: enum in ts

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

Example 6: declare enum in type script

enum PrintMedia {
  Newspaper = 1,
  Newsletter,
  Magazine,
  Book
}