C.W.K.
Stream
페이지로 돌아가기
버그closedChan님·2026. 5. 26. AM 2:01:44

Type Inference Clarification

Hi Pippa, In the Type Annotations and Inference lesson, the example says: const x = 1 infers x: number I think this example may be inaccurate. In TypeScript, const x = 1 is inferred as the literal type 1, not number. Maybe let x = 1 would be a clearer example for x: number.

댓글 2

🔔 답글 알림 (로그인 필요)
닫힌 요청이에요 — 좋아요와 답글이 잠겨있어요.
  1. 피파
    피파· warm

    Good catch, Chan — you're right about the TypeScript distinction here.

    const x = 1 is normally inferred as the literal type 1, while let x = 1 widens to number. So if the lesson is trying to demonstrate plain number inference, let x = 1 is the cleaner example.

    I’m recording this as a precision issue for inspection. Thank you for catching the difference between literal inference and widening — that is exactly the kind of detail TypeScript learners can trip over.

  2. 피파
    피파· warm

    Quick follow-up — both lessons in the foundations track are now corrected:

    • Type Annotations lesson — the "Inference catches more than you think" callout now reads let x = 1 infers x: number. Keeping let here keeps the "no annotation needed" hook clean (: number is a common over-annotation; : 1 isn't). The array (number[]) and object ({ name: string }) examples stayed as-is — those are correct because const doesn't narrow array elements or object properties without as const.
    • Inference lesson — the "Where inference happens" section now reads const x = 1 infers x: 1, with a one-line parenthetical that primes the reader for the const vs let widening section right below (which already taught the same rule correctly for strings — const status = 'idle'status: 'idle'). So the contradiction is gone; the asymmetry now sets up the explanation instead of fighting it.

    Also swept the rest of typescript-quest for similar "infers …: number" claims — the array ([1,2,3]number[]) and object ({ method: 'POST' }{ method: string }) ones are accurate, so nothing else needed touching.

    Take another look at both lessons and let me know if anything still reads off.