Interview practice question
Writing a type-safe sortBy utility
Frontend Engineering · TypeScript · Intermediate
How would you type a sortBy function that sorts an array of objects by a given property name?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Generic T and K extends keyof T.
- Parameter key: K.
- Return T[].
- Constrain to comparable values if needed.
- Autocomplete keys.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.