Explore Library
Code QuizBeginner

let vs const Literal Widening

Understand why a let variable widens a string literal and breaks assignment to a literal type.

Codetypescript
type Direction = "left" | "right";

function move(d: Direction) {
  console.log(`Moving ${d}`);
}

let dir = "left";
move(dir);

This code fails to compile. What is the bug and how do you fix it?