How TypeScript thinks · core
Types, interfaces and structural typing
TypeScript checks the shape of a value, not its name; type and interface both describe shapes, but only interfaces merge and only type aliases can name unions and other non-object types.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Structural typing: any value with the required properties fits, even if it was never declared with that type. Extra properties are only rejected for fresh object literals (excess property check).
interfacecan be extended withextendsand re-opened (declaration merging), which is how libraries let you add fields (e.g. toWindow).typecan name anything: unions, tuples, primitives, mapped and conditional types. Intersections (A & B) combine types.- Types exist only at compile time. They are erased: nothing in the emitted JavaScript checks them.
- Rule of thumb: interface for public object shapes that others extend; type for unions and computed types. Be consistent in a codebase.
The red pen
Common traps: mistake → fix
Mistake: "interface and type are the same"
Fix: only interfaces merge; only types can be unions or mapped/conditional types.
Mistake: "TypeScript checks types at runtime"
Fix: types are erased; runtime data from an API must be validated separately.
Easy to hard
Questions interviewers ask, easy to hard
- What is the difference between type and interface?
- What is structural typing? Give an example where it surprises people.
- What is declaration merging and when is it useful?
- Why does an extra property error on an object literal but not on a variable?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.