Q51: What is Type Widening in TypeScript?
Type Widening occurs when TypeScript expands a specific literal type (like 'hello') into a broader general type (like string) during variable declaration using let or var.
Type Widening Example
const x = "hello"; // Inferred as literal type: "hello"
let y = "hello"; // Widened to broader primitive type: string💡 Because y can be reassigned later, TypeScript widens its type to string.
Key Takeaways
- Reassignable variables are widened from literal types to primitive types.