Transform a Discriminated Union into a Union
Consider this discriminated union called Fruit
:
type Fruit = | { name: "apple" color: "red" } | { name: "banana" color: "yellow" } | { name: "orange" color: "orange" }
Challenge
Your challenge is to turn this discriminated unio
Transcript
0:00 The goal of this exercise is to take a discriminated union and turn it into a union. This seems like a really, really challenging task until you realize that, "OK, we can use the key remapping to iterate over this."
0:12 There is one really nice, beautiful solution to this. You'll need to use key remapping. You'll need to use the creation of that intermediary object and then accessing it with key of. Yeah, you'll need to use all of the pieces that you've used so far to come together for this solution.
0:31 Good luck.