TypeScript
Lesson 3 of 8
38%
Free Section Starter (Lesson 3)
TYPESCRIPT Free Section Starter Challenge 20 min

3. Union Types & Literal Enums

Overview: Restrain values with union types `type Status = "draft" | "published" | "archived"`.

Concept & Syntax Guide

Union types let you accept one of several specific values, replacing error-prone raw strings with compile-time checked constants.

Hands-On Practice Exercise

Validate Order License Type

Define a type `type License = "single" | "agency";` and write a function `getLabel(l: License)` that returns the string.

Target Output: Agency Unlimited
Need a hint? Click here to reveal
Hint: Check syntax carefully and make sure your code contains: Agency Unlimited
TYPESCRIPT Code Editor
1
2
3
4
5
6
7
8
9
10