Lesson 1 of 80
TypeScript decides if two types are compatible by comparing their shape, not their name — the same instinct as JavaScript's own duck typing, checked one phase earlier.
13 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
Two TypeScript interfaces, Point2D and Coordinate, have the exact same shape but were never declared as related. Can a Coordinate value be passed where a Point2D is expected?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
TypeScript's types exist only at compile time — they're checked, then completely erased before your code runs as plain JavaScript. Nothing about a type or interface survives into the actual .js output.
TypeScript decides whether two types are compatible using structural typing: it compares their shape — what properties and methods exist — not their declared name or where they came from. Two types with an identical shape are interchangeable, even if they were never declared as related.
interface Point2D {
x: number;
y: number;
}
interface Coordinate {
x: number;
y: number;
}
function distanceFromOrigin(p: Point2D): number {
return Math.sqrt(p.x ** 2 + p.y ** 2);
}
const c: Coordinate = { x: 3, y: 4 };
distanceFromOrigin(c); // ✅ fine — same shape, no relationship declared
Point2D and Coordinate share nothing but a name difference and an identical shape — and that's enough. TypeScript never asks "was this declared as a Coordinate?" — only "does it have an x: number and a y: number?"
Two interfaces, different names, identical shape: { x: number, y: number }.
distanceFromOrigin({ x: 1, y: 2, z: 3 }) is rejected for the extra z — but assigning that same object through a variable first (const p = { x: 1, y: 2, z: 3 }; distanceFromOrigin(p);) is allowed. This trips people up constantly; it's a deliberate extra check specifically for object literals, not a hole in structural typing.if (x instanceof SomeInterface) — interfaces are erased entirely by compile time. Runtime validation of untrusted data (like an API response) needs a separate tool (e.g. Zod) that actually checks shape while the code is running."Is TypeScript nominally or structurally typed?" tests whether you understand how TypeScript actually decides compatibility — and the honest, deeper answer connects it straight back to something you already know: JavaScript itself never cared about declared types either, just shape.