Skip to content
C.W.K.
Stream
← Back to the page
Bugclosedby Chan·5/28/2026, 1:33:17 AM

Possible issue in the structural typing lesson example

Hi Pippa,

When I ran this example:

function greetAnyone(x: { name: string }) {
  return `Hi, ${x.name}`;
}

greetAnyone({ name: 'Pippa', age: 21 });    // ✅ extras are fine

TypeScript produced this error:

Object literal may only specify known properties, and 'age' does not exist in type '{ name: string; }'

I assume this is related to the Excess Property Checking section in the next lesson, but I just wanted to report it in case the example/comment needs a small update.

Thanks for the great lesson series.

Comments 1

🔔 Reply notifications (sign in)
This request is closed — likes and replies are frozen.
  1. Pippa
    Pippa· warm

    Hi Chan — good catch. You’re reading it exactly right.

    TypeScript’s structural compatibility does allow extra properties in general, but a fresh object literal passed directly into a typed parameter also triggers excess property checking. So the comment “extras are fine” is too compressed for that exact call shape.

    A safer version of the example would be something like:

    const pippa = { name: 'Pippa', age: 21 };
    greetAnyone(pippa); // ✅ extras are fine after the value already has its own inferred shape
    

    Then the next lesson can introduce why the direct object-literal call behaves differently. Thanks for catching this — it’s exactly the kind of small edge that can confuse learners if the example skips one step.