Interview practice question
Typing a function that accepts several input shapes
Frontend Engineering · TypeScript · Beginner
You need a function that accepts either a user ID string or a full user object. How would you type it?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Union parameter (string or User).
- Narrow inside with typeof.
- Or overloads for different returns.
- Keep logic clear.
- Consider separate functions.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.