# The satisfies Operator

> Validate shape without losing literal types.

Subject: TypeScript | Lesson 54 of 54 | 4 min read
Interactive lesson: https://codewithanimation.in/typescript/satisfies-operator
Previous: [React Event Handlers](https://codewithanimation.in/typescript/react-event-handlers.md)

## The Widening Problem

When you annotate a variable with a type (`const colors: Theme = ...`), TypeScript validates that the object matches the `Theme` interface.

However, it also 'widens' the types of your properties. If `Theme` says `primary: string`, TypeScript forgets that you typed exactly `"blue"` and only remembers that it is some generic `string`.

## Enter 'satisfies'

Introduced in TypeScript 4.9, the `satisfies` operator solves this exact problem.

It checks that an object matches an interface, but it *preserves* the exact literal types of the values you assigned.

## Syntax

```typescript
type Theme = { primary: string, secondary: string };

// ❌ Widens to string
const badTheme: Theme = { primary: "blue", secondary: "red" };
badTheme.primary; // Type is 'string'

// ✅ Preserves exact literal
const goodTheme = { primary: "blue", secondary: "red" } satisfies Theme;
goodTheme.primary; // Type is strictly '"blue"'
```

## Common mistake: Why does it matter?

Imagine you have a function that only accepts specific colors: `function paint(color: "blue" | "red")`.

If you pass `badTheme.primary`, TypeScript throws an error because `string` is not guaranteed to be `"blue" | "red"`. If you pass `goodTheme.primary`, it works perfectly!

## Tip: Config Objects

The `satisfies` operator is incredibly popular for typing configuration objects (like Tailwind themes or routing maps) where you need validation but also strict autocomplete later on.

## Try it: Try it

Toggle between standard Type Annotation and the modern `satisfies` operator to see how it affects downstream type inference.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/typescript/satisfies-operator

## Check yourself

### Question 1

What is the key difference between Type Annotation (`: Type`) and the `satisfies` operator?

- A. Annotation checks types at runtime, satisfies checks at compile time.
- B. Annotation forces the variable to become the broader type, while satisfies validates the shape but preserves the narrow, exact literal types.
- C. They do exactly the same thing, satisfies is just newer syntax.

Correct answer: B

Annotation is destructive to literal types. It widens "blue" to string. Satisfies validates the object without destroying the highly-specific literal types you provided.

## Remember this

- `const x: Type = {}` widens your specific literal values.
- `const x = {} satisfies Type` validates the shape but preserves your exact literals.
- Use `satisfies` for configuration objects, themes, and route maps.
- It prevents errors when passing object properties into functions that expect strict union literals.
