Template Literals 7 exercises
Problem

Create a Union of Strings with All Possible Permutations of Two Unions

Here we have a Sandwich type that's currently assigned to unknown

We also have a couple of union types, BreadType and Filling, that have several options as members:


type BreadType = "rye" | "brown" | "white"
type Filling = "cheese" | "ham" | "salami"
type Sandwich = unknown

Loading exercise

Transcript

0:00 We're now going to examine the effect of unions inside template literals. Here, we have a sandwich type that we're trying to grab rye sandwich with cheese, rye sandwich with ham, rye sandwich with salami. We're basically taking all of these options and trying to map over them to create all of the permutations of them.

0:19 You might think this is pretty tricky, but the solution might surprise you. I would say, don't try too hard to create some crazy map type out of this. There's interesting properties of template literals that this exercise explores. Good luck.