TypeScript from JavaScript

Lesson 4 of 6

Enums and Advanced Types

Enums

An enum gives a set of related constants readable names.

TypeScript

Discriminated unions

Combining a union type with a shared "tag" property lets TypeScript narrow which shape you're working with.

TypeScript

The ok property is the discriminant, checking it narrows result to exactly one branch of the union inside each if.

📝 Enums & Unions Quiz

Passing score: 70%
  1. 1.What kind of type is `{ ok: true; data: T } | { ok: false; error: string }`?

  2. 2.The keyword used to define a set of named constants in TypeScript is ____.

  3. 3.Checking a shared property like `result.ok` lets TypeScript narrow the type inside an if branch.