Designing Your Types 11 exercises
Problem

Represent All Possible Type Combinations with Template Literals

In this exercise, we want to build a Sandwich type.

This Sandwich is expected to encompass all possible combinations of three types of bread ("rye", "brown", "white") and three types of filling ("cheese", "ham", "salami"):


type BreadType = "rye" | "brown" | "white";
type F

Loading exercise

Transcript

00:00 I've got a fun exercise for you here. We have a type of sandwich, and we're expecting the sandwich type to be equal to a bunch of different things. Rye sandwich with cheese, rye sandwich with ham, rye sandwich with salami, brown sandwich with cheese, brown sandwich with ham, brown sandwich with salami. Basically, all the possible combinations of rye, brown, white, and cheese, ham, salami,

00:18 which ends up being these various possibilities. Your job is to try to work out the most efficient way to type this sandwich type while essentially using as few lines of code as possible. You can do this in a single line of code using template literal types. Good luck.