Structural typing means compatibility is decided by shape, not by declared name, so any object with the right properties satisfies the type. That makes types cheap and composable, but it also means two unrelated concepts with the same shape are interchangeable, so a userId string can be passed where an orderId string is expected. The usual fix is a branded type or a small wrapper that gives the value a distinct shape.
Why interviewers ask this
It separates people who add annotations until the red squiggles stop from people who use the type system to prevent classes of bugs. The interviewer is checking whether you know that types are erased at runtime, that excess property checks only fire on object literals, and how to model a domain so wrong values are unrepresentable. It usually leads into discriminated unions and validation at the boundary.
How to structure your answer
- Define structural typing in one sentence and contrast it with nominal typing.
- Give the failure case: two identical shapes that mean different things.
- Explain the branded type or wrapper fix.
- Note that types vanish at runtime, so boundaries still need validation.
Example answer
It means TypeScript compares shapes, not names, so if something has the right properties it is assignable, no matter where it came from. That is mostly a gift, since it makes types feel like documentation rather than ceremony. Where it bites is when two types are the same shape but different concepts. All of my ids were plain strings, so passing a user id into a function expecting an order id compiled perfectly and failed in production. I fixed it with branded types, an intersection with a unique tag that only a constructor function can produce, so the compiler stops treating them as the same. The other trap is that types are erased, so nothing checks the response from an API at runtime. I parse anything crossing a boundary with a schema validator and let the inferred type flow from that, which means the type and the actual data cannot drift. And I know excess property checking only applies to fresh object literals, which explains a lot of confusion about why an extra field is sometimes an error and sometimes not.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How would you implement a branded type without a runtime cost?
- When do you use unknown rather than any, and what forces you to narrow?
- How do you keep API types honest at runtime?
Related frontend developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions