Q03. What is type inference?
Type inference is the compiler's ability to derive types from initializers, expressions, and contextual information. It reduces annotation noise while preserving static checking. Public boundaries and complex APIs may still benefit from explicit annotations.
The compiler infers count as a number from its initializer. Contextual typing can infer callback parameters from the API receiving the callback.
Note
Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.
Inference
const count = 10;
const label = "ready";💡 The compiler derives useful types from initializers.
Key Takeaways
- Explain the concept in your own words.
- Know the practical trade-off and its limits.
- Use a small example to demonstrate the idea.
Knowledge Check
What is inferred for `const count = 10` in ordinary code?