CodePark/ questions / Types vs interfaces
START PRACTICINGPRACTICE
Frontend question · TypeScript › Types vs interfaces

Which line produces a compile error?

type Point = { x: number; y: number };
const a: Point = { x: 1, y: 2, z: 3 };   // Line 2
const raw = { x: 1, y: 2, z: 3 };
const b: Point = raw;                    // Line 4
Only Line 2

Only Line 2 errors. It assigns a fresh object literal, so the excess property check flags z.

"Both lines" is wrong because Line 4 assigns a variable. A variable gets only the normal structural check.
raw has x and y, so the extra z is allowed.