Course contentsShow
← TypeScript
Lesson 322 of 1,7967. ObjectsFree lesson

What Are Excess Property Checks

Understanding how TypeScript catches extra properties in object literals that don't match the target type.

What Are Excess Property Checks

You'll learn how TypeScript catches extra properties in object literals that don't match the target type.

The Core Idea

When you assign an object literal directly to a typed variable or pass it directly to a function, TypeScript performs excess property checks. This means it rejects any properties that aren't defined in the target type, even if structural typing would normally allow it.

Think of it like a bouncer at a club checking IDs. Normally, TypeScript uses "structural typing" — if you have the right features (required properties), you're in. But with object literals, the bouncer also asks: "Why do you have these extra items in your pockets?" Extra properties suggest you might be confused about what type you're creating.

Why This Matters

Without excess property checks, typos in property names would silently pass through:

interface Person {
  name: string;
  age: number;
}

// ❌ Error: Object literal may only specify known properties
const user: Person = {
  name: "Alice",
  age: 30,
  job: "Engineer"  // Excess property 'job'
};

This catches mistakes early. You probably meant to use a different type, or you made a typo.

When It Applies

Excess property checks only trigger with fresh object literals:

const obj = { name: "Bob", age: 25, job: "Designer" };
const person: Person = obj;  // ✅ OK - not a fresh object literal

Once the object is assigned to a variable first, TypeScript falls back to structural typing and only checks that required properties exist.

Key Takeaway: Excess property checks catch typos and mismatched object literals by rejecting extra properties when you directly assign or pass object literals to typed locations.