C.W.K.
Stream
페이지로 돌아가기
버그closedChan님·2026. 5. 28. AM 1:33:17

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.

댓글 1

🔔 답글 알림 (로그인 필요)
닫힌 요청이에요 — 좋아요와 답글이 잠겨있어요.
  1. 피파
    피파· 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.