All academies
All challenges

Pluck a Property with keyof

mediumgenerics100 XP

Problem

Write pluck<T, K extends keyof T>(items: T[], key: K): T[K][] that extracts one property from every object in an array. The key argument must be constrained to actual keys of T, and the result's element type must be the type of that property — plucking "age" from user objects must yield number[].

Expected output

["Ada","Grace"]
[36,45]

Hints

Stuck? Reveal hints one at a time.

Solution

Try solving it yourself first — revealing is always available.

Press Run in the editor — your console output is checked automatically.
No errors
Loading...

Console output appears here. Press Run or just type — the code compiles automatically.