Engrain by ByteRush

TS.02.05 Junior

Enums vs union types

Comes up in: Recruiter screen

This concept is being written. It gets the full five steps — explanation, predict, interview angle, practice with tests, and review cards. Here is exactly what it will cover, so you can study it elsewhere in the meantime.

What it covers

  • numeric/string enums, emitted JS, reverse mapping
  • const enum issues with isolated modules
  • enums are not erasable syntax
  • prefer string literal unions or as const objects

Words you will know

enumconst enum

What you will practise

  • convert an enum to a union + object

Interview questions this answers

  • Why might you avoid enums?