AI Hints
Home›TypeScript Tutorial›Type Guards and Practice
TypeScript · Lesson 39 of 120

Unions Quiz

Test yourself.

⏱ 2 min read▶ Video at 30:39🎓 Free
Watch this lesson in the TypeScript courseWatch on YouTube ↗Full TypeScript course

Let's review unions and narrowing. Pause after each question, and answer before I do.

Unions Quiz
From the video: Unions Quiz
  • Unions quiz
  • Pause and think
  • Then check

Question 1

How do you write number or string? With a vertical bar between them.

Quick check
Number or string is:

Question 2

Which check narrows a union of object shapes by a property? The in operator.

Quick check
To check for a property, use:

Question 3

What's the shared literal field in a discriminated union often called? Kind.

Quick check
The shared field is often:

Question 4

What type makes switches exhaustive? Never.

Quick check
Exhaustive checks assign to:

Summary

Well done. Next, enums.

Key takeaways
  • |
  • in
  • never
Next up: Enums — named constants