# Literal Types — TypeScript

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

> A type that allows only specific, exact values.

## 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.
