Command Palette

Search for a command to run...

Hectal
Phase 7: Generics
TypeScript · Exercise 2 of 6 PreviousNext
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

  1. Your code has no type errors
  2. The console prints both lists
  3. Names come back as string[]
  4. Ages come back as number[]
  5. Names are not number[]
  6. A key that does not exist is rejected
  7. No any and no as

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.

Console

Nothing printed yet.