Unions and Indexing 10 exercises
Problem

Extract the Discriminator from a Discriminated Union

In this exercise, we have the same Event discriminated union that we’ve used before:


export type Event =
| {
type: "click"
event: MouseEvent
}
| {
type: "focus"
event: FocusEvent
}
| {
type: "keydown"
event: KeyboardEvent
}

Your jo

Loading exercise

Transcript

0:00 In this exercise, we have a discriminated union, the same one that you've seen before. What I'd like you to do is grab out the type here of click or focus or keydown from the discriminated union.

0:13 This exercise is actually easier than it seems, so don't go too deep into anything too crazy. All of the pieces that you need for this have been covered before. Good luck.