Intermediate
Pluck a Property
pluck should return one property from every item in a list. Right now it takes any object and a plain string key, so it returns unknown[] and accepts keys that don't exist.
Make it generic with T for the item and K extends keyof T for the key. The result must be T[K][]. The checks use the users array and call pluck with good and bad keys.
What Check tests
- Your code has no type errors
- The console prints both lists
- Names come back as
string[] - Ages come back as
number[] - Names are not
number[] - A key that does not exist is rejected
- No
anyand noas
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Press Run to see the page.
Console
Nothing printed yet.