

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Unions
incomplete
2: Optional Parameters
incomplete
3: Default Parameters
incomplete
4: Literal Types
incomplete
5: Value Unions
incomplete
6: Template Literal Types
incomplete
7: Giant Unions
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Take another look at our last example of a literal type:
function move(direction: "north") {
// Implementation...
}
To make it a bit more useful, let's combine that idea with a union type:
function move(direction: "north" | "south" | "east" | "west") {
// Implementation...
}
And then let's refactor it to make a new "Direction" type that we can reuse:
type Direction = "north" | "south" | "east" | "west";
function move(direction: Direction) {
// Implementation...
}
At Support.ai, we're building a ticket prioritization system that needs a consistent way to categorize tickets by importance.
lowmediumhighcriticallow returns 0medium returns 1high returns 2critical returns 30The default case is needed so that the function's inferred return type doesn't include undefined.