Skip to main content

Lesson 7 of 8

The `satisfies` Operator (TypeScript 4.9+)

The `satisfies` operator validates that a value matches a type without widening the value's inferred type. It's a solution to a long-standing problem: annotating objects where you want type-checking of the values but also want to preserve literal types for later use.

9 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

satisfies - Validation Without Widening

satisfies - Validation Without Widening
// ── Problem satisfies solves ─────────────────────────────────

// Option 1: Explicit annotation - validates, but WIDENS the type
const config: Record<string, string | number> = {
  port:    3000,
  host:    "localhost",
  debug:   "true",
};
// config.port is typed as string | number - we lost "it's a number"

// Option 2: No annotation - preserves literal types, but no validation
const config2 = {
  port:  3000,
  host:  "localhost",
  debug: "true",
};
// config2.port is number ✅ - but no type check ensures values are string|number

// Option 3: satisfies - validates AND preserves narrow types ✅
const config3 = {
  port:  3000,
  host:  "localhost",
  debug: "true",
} satisfies Record<string, string | number>;

config3.port.toFixed(2);     // ✅ TypeScript knows it's number, not string|number
config3.host.toUpperCase();  // ✅ TypeScript knows it's string

// If validation fails:
const badConfig = {
  port: true,    // ❌ Error: boolean is not assignable to string | number
} satisfies Record<string, string | number>;

// ── Real-world: route config ──────────────────────────────────
type RouteConfig = {
  path: string;
  method: "GET" | "POST" | "PUT" | "DELETE";
  auth: boolean;
};

const routes = {
  createTask: { path: "/tasks",     method: "POST", auth: true  },
  listTasks:  { path: "/tasks",     method: "GET",  auth: false },
  deleteTask: { path: "/tasks/:id", method: "DELETE", auth: true },
} satisfies Record<string, RouteConfig>;

// TypeScript still knows routes.createTask.method is "POST", not just HttpMethod
type CreateMethod = typeof routes.createTask.method;  // "POST", not HttpMethod

Common Mistakes

  • Using `as` instead of `satisfies` - `as` casts the type and suppresses errors. `satisfies` validates the type and preserves the narrow inferred type. Always prefer `satisfies` when you want both validation and precision.
  • Not knowing when to use `satisfies` vs explicit annotation - use `satisfies` when you want the compiler to check your object against a contract AND you need the narrow inferred types afterward. Use explicit annotation when you explicitly want the wider type (e.g., the type might change at runtime).
  • `satisfies` is not `as const` - they do different things. Combine them: `{ ...obj } satisfies Config as const` if you need both validation and full literal freezing.

Tip

Tip

Practice The in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Visual architecture and concepts for The `satisfies` Operator (TypeScript 4.9+)

Practice Task

Note

Practice Task - (1) Write a working example of The from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with The is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready typescript code.

Key Takeaways

  • The `satisfies` operator validates that a value matches a type without widening the value's inferred type.
  • Using `as` instead of `satisfies` - `as` casts the type and suppresses errors. `satisfies` validates the type and preserves the narrow inferred type. Always prefer `satisfies` when you want both validation and precision.
  • Not knowing when to use `satisfies` vs explicit annotation - use `satisfies` when you want the compiler to check your object against a contract AND you need the narrow inferred types afterward. Use explicit annotation when you explicitly want the wider type (e.g., the type might change at runtime).
  • `satisfies` is not `as const` - they do different things. Combine them: `{ ...obj } satisfies Config as const` if you need both validation and full literal freezing.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/8 done