DEV Community

Discussion on: TypeScript: How to use Enums

Collapse
peerreynders profile image
peerreynders

... and the obligatory Objects vs Enums

const EEVEELUTIONS = {
  Eevee: 133,
  Vaporeon: 134,
  Jolteon: 135,
  Flareon: 136,
  Espeon: 196,
  Umbreon: 197,
  Leafeon: 470,
  Glaceon: 471,
  Sylveon: 700,
} as const;

// Resulting in
// type Eeveelutions = 133 | 134 | 135 | 136 | 196 | 197 | 470 | 471 | 700
type Eeveelutions = typeof EEVEELUTIONS[keyof typeof EEVEELUTIONS];

const basicPokemon = EEVEELUTIONS.Eevee;
console.log(basicPokemon);
const Sylveon = EEVEELUTIONS.Sylveon;
console.log(Sylveon);
Enter fullscreen mode Exit fullscreen mode