# Generics: exercises

1. Write `first<T>(items: T[]): T | undefined` and check that `first([1, 2])` is `number | undefined`.
2. Write `pluck<T, K extends keyof T>(items: T[], key: K): T[K][]`.
3. Make `groupBy` return `Record<string, T[]>` and make the key function generic.
4. Bonus: type a `useLocalStorage<T>(key, initial)` hook so the setter only accepts `T`.

Solutions are in the starter project under `solutions/generics.ts`.
