TYPESCRIPT

TypeScript satisfies Operator: Purpose, Usage, and Examples

The TypeScript satisfies operator is a relatively new feature introduced in TypeScript 4.9. It provides a powerful way to ensure that a value conforms to a specific type without widening the type of the variable itself. This is particularly useful for type checking while preserving the most specific inferred type available for the value.

Using satisfies TypeScript allows developers to gain stronger type safety, clearer intent, and better tooling support. Unlike using a simple type annotation, the satisfies keyword doesn't affect the inferred type—it only checks compatibility. This leads to more robust and flexible code, especially when working with constants, objects, or utility types.

This guide explains how satisfies works, how it compares to annotations and type assertions, and how to use it in practical TypeScript codebases.


What Is the satisfies Operator in TypeScript?

The satisfies operator checks that an expression matches a given type while keeping the inferred type intact.

Basic Syntax:

const value = expression satisfies Type;

This allows the compiler to enforce that expression meets all the requirements of Type, but value will still retain its specific inferred type instead of being upcasted.


Example: Type Preservation

Using TypeScript satisfies preserves narrow types, unlike annotations that force widening.

const directions = ["north", "south", "east", "west"] as const;

// Without `satisfies`
const obj1: Record<string, string> = {
  north: "up",
  south: "down",
  east: "right",
  west: "left",
};

// With `satisfies`
const obj2 = {
  north: "up",
  south: "down",
  east: "right",
  west: "left",
} satisfies Record<(typeof directions)[number], string>;

In this example, obj2 is fully checked against the type, but its own type remains literal, allowing better inference and stricter type safety.


How to Use satisfies in TypeScript

You can use satisfies in various places where type safety is important but you don’t want to lose type inference.

Use Case: Validating Object Shape

type User = {
  id: number;
  name: string;
};

const user = {
  id: 1,
  name: "Alice",
} satisfies User;

The object must fully match the User interface. If a property is missing or mistyped, TypeScript will throw an error.


Enforcing Exhaustive Object Keys

One of the most common uses of satisfies TypeScript is to ensure that all expected keys are covered without losing key-specific information.

const statuses = {
  idle: "Not started",
  loading: "Fetching data",
  success: "Done",
  error: "Failed",
} satisfies Record<"idle" | "loading" | "success" | "error", string>;

If you miss a key or add an unexpected one, the compiler will alert you.


Combining with as const

The satisfies operator pairs extremely well with as const to maintain literal types.

const colors = {
  primary: "#000",
  secondary: "#FFF",
} as const satisfies Record<string, string>;

This keeps the colors object's values as literal strings ("#000" and "#FFF") while checking them against the broader Record<string, string> structure.


Working with Arrays

You can also use satisfies to validate that an array matches a certain type without losing tuple information.

const roles = ["admin", "editor", "viewer"] as const;

const permissions = {
  admin: true,
  editor: true,
  viewer: false,
} satisfies Record<(typeof roles)[number], boolean>;

In this how to use satisfies TypeScript pattern, you're dynamically constructing types based on array contents and ensuring the object respects that structure.


Differences from Type Assertions

Type assertions (as Type) tell the compiler to trust you, while satisfies checks the value's validity at compile time.

const obj1 = { x: 10 } as { x: number; y: number }; // No error, but y is missing
const obj2 = { x: 10 } satisfies { x: number; y: number }; // Error: y is missing

Using satisfies avoids the silent failure risks of assertions by verifying the type constraints during development.


Differences from Type Annotations

Annotations like const x: Type = value assign the type to x and override what TypeScript would have inferred. satisfies only checks but doesn’t override.

const value = {
  role: "admin",
} satisfies { role: string }; // `role` stays "admin"

const typed: { role: string } = {
  role: "admin",
}; // `role` becomes type string, losing literal "admin"

This distinction is critical for maintaining precise type information while ensuring conformity.


Practical Use Cases

1. Validating Config Files

const config = {
  apiUrl: "https://example.com",
  timeout: 5000,
} satisfies {
  apiUrl: string;
  timeout: number;
};

This guarantees structure adherence without sacrificing the specificity of the values.

2. Static Maps with Enum Keys

enum Status {
  Open = "open",
  Closed = "closed",
}

const labels = {
  open: "Open case",
  closed: "Closed case",
} satisfies Record<Status, string>;

This is useful in prettier TypeScript satisfies configurations, linters, or strongly typed design tokens.


Benefits of Using satisfies in TypeScript

  • Improved Type Safety: Ensures that values meet expected structure without silently failing.
  • Better Inference: Maintains literal or tuple types, unlike annotations.
  • Great for Constants: Works best with objects, arrays, or enums where shape matters.
  • Safe for Validation: Eliminates unsafe type assertions and improves reliability of internal tooling.

Limitations

  • Only Works with Assignable Types: If the value isn’t assignable to the target type, compilation will fail.
  • Not a Runtime Feature: The satisfies operator is compile-time only and has no output in JavaScript.
  • Can’t Be Used for Runtime Checks: Use it purely for development-time guarantees.

Tips for Using satisfies Effectively

  • Use with as const for best results.
  • Prefer over type assertions when validating shape.
  • Combine with generics to validate derived structures.
  • Avoid using in dynamic or computed properties—it's most effective for static objects.

Summary

The TypeScript satisfies operator is a highly useful tool for validating that a value matches a certain type while maintaining precise inferred types. Unlike annotations or assertions, satisfies TypeScript introduces stricter compile-time checks that improve reliability without sacrificing flexibility.

You can use it to ensure config structures, map objects to enums, preserve literal values, and validate array patterns.

Learn TypeScript for Free
Start learning now
button icon
To advance beyond this tutorial and learn TypeScript by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2025 Mimo GmbH

Reach your coding goals faster