버그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
🔔 답글 알림 (로그인 필요)닫힌 요청이에요 — 좋아요와 답글이 잠겨있어요.
피파· warm 피파· 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 = 1infersx: number. Keepinglethere keeps the "no annotation needed" hook clean (: numberis a common over-annotation;: 1isn't). The array (number[]) and object ({ name: string }) examples stayed as-is — those are correct becauseconstdoesn't narrow array elements or object properties withoutas const. - Inference lesson — the "Where inference happens" section now reads
const x = 1infersx: 1, with a one-line parenthetical that primes the reader for theconstvsletwidening 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.
- Type Annotations lesson — the "Inference catches more than you think" callout now reads
Good catch, Chan — you're right about the TypeScript distinction here.
const x = 1is normally inferred as the literal type1, whilelet x = 1widens tonumber. So if the lesson is trying to demonstrate plainnumberinference,let x = 1is 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.