TypeScript · 14-day planAll days
Day 6 of 14 30 mintypeof & inType guardsnever
Help TypeScript work out the exact type at each point in your code. Narrow unions with typeof, instanceof, in, equality and truthiness checks, switch on discriminants, write your own type guards, and make sure every case is handled.
By the end of today you can
- Narrow unions with typeof, instanceof, in and equality checks
- Use truthiness checks safely, knowing the 0 and empty string trap
- Narrow discriminated unions with switch
- Write type predicates (custom type guards)
- Use never for exhaustiveness checks
What's inside
- 6 sections
- 2 diagrams and mind maps
- 6 code examples you can run
- 5-question quiz
- 1How narrowing works
- 2typeof, instanceof and in
- 3Equality and truthiness
- 4Narrowing discriminated unions with switch
- 5Exhaustiveness checks with never
- 6Custom type guards
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free