ProgramGuru

The satisfies Operator

Understand The satisfies Operator

The satisfies operator checks that an expression is compatible with a specified type while retaining the expression’s more specific inferred type.

What you will learn: the purpose of the satisfies operator, the rules TypeScript checks, and what its JavaScript behavior looks like in a runnable example.

What you’ll learn

  • Explain how the satisfies operator works and where its type rules apply.
  • Predict the exact output of the the satisfies operator example.
  • Diagnose a common issue: Do not confuse satisfies with a runtime schema validator or a type assertion.

Build the mental model

It is useful for configuration maps and literal objects where an annotation might widen property access types. Unlike an as assertion, satisfies validates compatibility rather than simply asking the checker to trust your claimed type. It does not validate runtime data.

Key distinction: TypeScript checks the declared types during development; emitted JavaScript carries out the value-level operation at runtime. A type declaration alone never validates untrusted runtime input.

See the relationship

Read this illustration from the first labeled part to the last. Compare it with the example and identify which parts are type checks and which parts run in JavaScript.

The satisfies Operator: explained visuallyExpression inferred → satisfies Contract → Type is checkedExpression inferredsatisfies ContractType is checkedType-level rules are checked before JavaScript runs
The satisfies Operator: Expression inferred → satisfies Contract → Type is checked.

Run the complete TypeScript example

This self-contained example uses fixed values, so it runs without reading input or depending on an external service. Paste it into the TypeScript Playground or save it as main.ts.

TypeScript program

type Theme = { primary: string; spacing: number };
const theme = {
  primary: "#2563eb",
  spacing: 8
} satisfies Theme;
console.log(theme.primary.toUpperCase());
console.log(theme.spacing * 2);

Verified output

#2563EB
16

Run locally: npx tsc --strict --target es2022 --module commonjs main.ts, then node main.js. For projects with a tsconfig.json, build using that configuration instead.

Trace every important step

The expression is checked against Theme and retains useful inferred property types. The string method produces #2563EB, and spacing doubled gives 16.

Check each step: identify the input values, follow the JavaScript operation in execution order, and match the final expression with the exact output shown. An annotation can reject invalid source before execution, but does not change the value printed.

Avoid these common mistakes

Do not confuse satisfies with a runtime schema validator or a type assertion. A misspelled required key is a compile-time error for a fresh object literal.

How to debug: reproduce the issue in a minimal example. For compiler errors, inspect the inferred and declared types; for a runtime surprise, log the actual values and follow their references or branches.

Practice and experiment

Create a typed configuration with retries: number and mode: "dev" | "prod" using satisfies, then intentionally misspell a key.

Practice routine: predict the result on paper, edit one part of the code, compile under --strict, run the JavaScript, and explain whether TypeScript caught an error or JavaScript simply behaved differently.

Check your understanding

What is the principal use of satisfies?
Choose one answer. You can try again.

Answer and explanation

Check compatibility without replacing the expression’s inferred type with the target type.

The satisfies operator checks that an expression is compatible with a specified type while retaining the expression’s more specific inferred type.

Review the key idea

The satisfies Operator: The satisfies operator checks that an expression is compatible with a specified type while retaining the expression’s more specific inferred type.

The expression is checked against Theme and retains useful inferred property types. The string method produces #2563EB, and spacing doubled gives 16.

Before continuing, explain one valid use case, one common pitfall, and the separation between compile-time checking and runtime behavior for this feature.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Union Types →