# Literal Types — TypeScript Fundamentals

Source: https://www.skillbyai.com/en/typescript/ts-literal-types

> Restrict values to exact strings or numbers with literal types, and understand const versus let inference.

## Exact allowed values

A literal union restricts a value to a fixed set of strings or numbers — like a lightweight enum.

```typescript
type Direction = "up" | "down" | "left" | "right";

function move(dir: Direction) { /* ... */ }
move("up");      // OK
move("diagonal");
// Error: Argument of type '"diagonal"' is not assignable to type 'Direction'.
```

## const and literal widening

`let x = "up"` infers as `string`, but `const x = "up"` infers as the literal `"up"` — `const` can't be reassigned, so TS keeps the narrower type.
