Engrain by ByteRush

TS.02.01 JuniorCore — asked often

Unions, literals and narrowing

Comes up in: Recruiter screen, Coding

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

  • typeof, instanceof, in, equality and truthiness narrowing
  • control-flow analysis
  • assignment narrowing
  • narrowing pitfalls (typeof null, truthiness of 0/"")

Words you will know

narrowingcontrol-flow analysistype guard

What you will practise

  • narrow API results
  • fix 5 narrowing bugs

Interview questions this answers

  • How do you make the compiler warn when a new case is not handled?
  • What is a type guard? Write one.