Course contentsShow
← TypeScript
Lesson 463 of 1,79611. Literal TypesFree lesson

Widening from Literals to Primitives

Understand how TypeScript widens let declarations from literals to general string or number types.

Widening from Literals to Primitives

You'll learn: How TypeScript automatically broadens let variable types from specific literal values to general primitive types.

When you declare a variable with let and assign it a literal value, TypeScript doesn't lock the type to that exact value—it widens it to the broader primitive type.

The Core Concept

Think of literal types as specific addresses: "123 Main Street." When you use const, TypeScript remembers that exact address. But when you use let, TypeScript assumes you might want to store any address later, so it remembers the general category: "a string."

let city = "Boston";  // Type: string (widened!)
const state = "MA";   // Type: "MA" (literal)

let population = 700000;  // Type: number (widened!)
const founded = 1630;     // Type: 1630 (literal)

Notice how city has type string, not "Boston". TypeScript widened the literal "Boston" to the primitive string because let signals the variable is reassignable.

Why Widening Happens

Since let variables can be reassigned, TypeScript infers the general type you'll likely want:

let status = "pending";  // Type: string
status = "complete";     // ✓ Works fine
status = "error";        // ✓ Also works

If TypeScript kept the literal type "pending", you couldn't reassign status to any other string!

Key Takeaway: TypeScript widens let declarations from literal values to their primitive types (string, number, boolean) to allow reassignment, while const preserves the exact literal type.