Skip to content

Instantly share code, notes, and snippets.

@killerchip
Last active April 29, 2018 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save killerchip/3a0438acc0a048ef2e24443fc8770101 to your computer and use it in GitHub Desktop.
Save killerchip/3a0438acc0a048ef2e24443fc8770101 to your computer and use it in GitHub Desktop.
Typescript cheatsheet: Enums

Enums

Defining an Enum

// Simple Enum
enum Role {Employee, Manager, Admin}

// Custom start value
enum RolesCustomStart {Employee = 3, Manager, Admin}

// Custom values
enum RoleCustomValues {Employee = 3, Manager = 5, Admin = 7}

Using Enum

const role = Role.Manager;

Finding Enum description by value

console.log ( Role[1]); // 'Manager'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment