TypeScript Essentials

Lesson 05 · 12 min

Unions and narrowing

The main TypeScript skill. Everything else derives from it.

12 minLesson 5 of 10Practice includedAsk AI on any point

A union means "one of". After string | number TS won't let you call .toUpperCase() until you prove it's a string. That's narrowing: narrowing a type with a check. A method has to exist on every member of the union — otherwise branch first.

Sign in to continue

The rest of this lesson opens after sign up

The first lesson of every course is open without an account. To read on, solve the practice and use Ask, create a free account or log in.