TypeScript · Junior · Question 5 of 75
What type does TypeScript infer for let x = 5;?
- ✓Correct answer:
number - 2
5(a literal type) - 3
any(no annotation)
Explanation
Type inference: for let, the literal widens to number because the variable can be reassigned. For const x = 5, the type is the literal 5. Explicit annotations are needed where inference is impossible or imprecise - e.g. in function parameters.