What is ‘type widening’ in TypeScript and when does it occur?

TypeScript Professional Medium

TypeScript Professional — Medium

What is ‘type widening’ in TypeScript and when does it occur?

Key points

  • Type widening happens when a literal type like 'hello' is automatically widened to its primitive type string.
  • It occurs specifically when a variable is declared with 'let' without specifying a type.
  • This feature helps TypeScript maintain type compatibility and flexibility in variable assignments.

Ready to go further?

Related questions