Unions and Indexing 10 exercises

Create a Union From an Object's Values

This exercise starts with our programModeEnumMap that includes the as const annotation.

export const programModeEnumMap = {
GROUP: "group",
ANNOUNCEMENT: "announcement",
ONE_ON_ONE: "1on1",
SELF_DIRECTED: "selfDirected",
PLANNED_ONE_ON_ONE: "planned1on1",

Loading exercise


0:00 Here's another problem that starts with our programModeEnumMap. We've got our as const declaration here, which is great. We've now got all the values available to us, but we want to index into it and grab out a union type from it.

0:20 We want 1on1 or selfDirected or planned1on1 or plannedSelfDirected. We want this one or this one or this one or this one, basically anything that's not a group activity, for instance, so all of these are 1on1.

0:35 We need to somehow do that within this value here, so we need to replace this unknown with the thing that we think is going to work here. Again, this one is slightly simpler than you think it's going to be, but it also does introduce something new.

0:50 Good luck with this. This one is quite tricky.