Structural typing & excess property checks
Understand structural typing in TypeScript and how excess property checks prevent unintended object shapes.
Intro
Goal: Learn structural typing, where compatibility depends on having the right members, and how excess property checks work with object literals.
Structural typing
Structural typing: compatibility is by shape. If an object has at least the required properties, it is accepted, even if extra ones exist.
interface Point { x: number; y: number; }
function logPoint(p: Point) {
console.log(p.x, p.y);
}
const a = { x: 5, y: 7, z: 99 };
logPoint(a); // OK because it has x and yAll lessons in this course
- Object types, optional/readonly, index signatures
- Interfaces vs Type Aliases
- Structural typing & excess property checks