Interview practice question
Preventing mix-ups between different ID types
Frontend Engineering · TypeScript · Intermediate
A bug occurred because a function received an order ID where a user ID was expected; both are strings. How can TypeScript prevent this?
What a strong answer covers
Your AI report card counts how many of these ideas you cover.
- Structural typing treats both as string.
- Branded types: string & { __brand: "UserId" }.
- Constructor/validation functions create brands.
- Zero runtime cost.
- Apply to critical IDs.
Practise this topic
Start without signing up. Sign in free to get an AI report card on your answer.