The Art of Type Arguments 9 exercises

Typed Object Keys

Here we have a function called typedObjectKeys.

The function takes in an object, and grabs the keys from it, then returns them:

Loading exercise


0:00 In this exercise, we have a function called typedObjectKeys where we receive an object, and we want to grab the keys from it and return them. Object.keys by default it returns string here or rather an array of strings. There's a very good reason for that which we can touch on and explain it. I might cover in an article too actually.

0:20 What we want to do is we want to return the object keys and we want result1 here instead of string array, we want it to equal array "a" or "b". Just like the previous exercise, you should probably be thinking about where you want to put the generic here. There may be options in terms of what you can represent in the generic slot, and remember, lower is better.

0:45 Good luck.