Mapped Types 9 exercises

Transforming Object Keys in Mapped Types

Let’s continue with the Attributes interface and the AttributeGetters helper from the previous exercise:

interface Attributes {
firstName: string
lastName: string
age: number
type AttributeGetters = {
[K in keyof Attributes]: () => Attributes[K]


We’ve crea

Loading exercise


0:00 This exercise starts as the previous exercise ended, where we have a set of Attributes and a set of AttributeGetters. We're started from the exact same solution except now that the game has changed a little bit.

0:13 We now want to create a getFirstName() function, getLastName() function, and getAge() function, whereas, in the previous exercise, what we had was just firstName, lastName, and age. We're wanting to remap the key a little bit.

0:30 We need to find a way within this structure here to take this key and remap it to something else, to a different key, because what we're needing to do is create getFirstName() out of firstName. Again, make sure you don't change this. The only thing you'll need to change is something on this line. Good luck.