Engrain by ByteRush

TS.02 5 concepts · 3 ready

Everyday types and narrowing

Model real data with unions, literals and narrowing.

  1. TS.02.01Unions, literals and narrowingCoreJuniorBeing written
  2. TS.02.02Discriminated unions and exhaustive checksCoreMid-level10 min
  3. TS.02.03User-defined type guards and assertion functionsCoreMid-level10 min
  4. TS.02.04as const, satisfies and literal inferenceCoreMid-level10 min
  5. TS.02.05Enums vs union typesJuniorBeing written

Interview questions in this module

  1. What is a discriminated union? Show how you model a request state.
  2. How do you make the compiler warn when a new case is not handled?
  3. What is a type guard? Write one.
  4. What is the difference between satisfies, a type annotation and as?
  5. Why might you avoid enums?
  6. What does as const do?