Mapped Types 9 exercises

Map Over a Union to Create an Object

We start with several routes in a union of strings called Route and an empty type helper called RoutesObject:

type Route = "/" | "/about" | "/admin" | "/admin/users"
type RoutesObject = unknown


Your challenge is to update the RoutesObject so that it becomes an objec

Loading exercise


0:00 We're now getting into the section of Total TypeScript that's about object types.

0:04 Here we've got a bunch of different routes in a string union. We want to create an object out of them where both the keys and the values are equal to the members of the union. That means, conceptually, we need to map over each one of these members of this union and put them in both the key and the value.

0:23 This is what's called a mapped type. That's what you're going to be needing to look in the TypeScript documentation for or look at articles online to help you with. You need to be changing the route object into a map type which maps over each route and puts it in the key and the value.

0:38 Good luck.