Pluck with keyof
Medium · Generics
Write pluck<T, K extends keyof T>(items: T[], key: K): T[K][] that returns the value of key from every item.
The keyof constraint makes sure you can only pass keys that exist on the items.
Medium · Generics
Write pluck<T, K extends keyof T>(items: T[], key: K): T[K][] that returns the value of key from every item.
The keyof constraint makes sure you can only pass keys that exist on the items.