TypeScript Reference ยท Type Operators
The satisfies operator
Reference for the TypeScript satisfies operator (4.9+): validate a value against a type while keeping its precise inferred type, with as const and annotation comparisons.
expr satisfies Type checks that expr is assignable to Type and reports an error if it is not, but it does not change the type of expr. The value keeps the precise type the compiler inferred from it. An annotation (const x: Type = ...) does the opposite: it checks and then widens the variable to Type.
That makes satisfies ideal for configuration tables and lookup objects, where you want typos and wrong value types caught while still remembering the exact keys and literal values you wrote.
const palette = { red: [255, 0, 0], green: "#00ff00", } satisfies Record<string, string | number[]>;
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
const value = expression satisfies Type;
| Part | Description |
|---|---|
expression |
Any expression. Its inferred type is kept. |
Type |
The contract the expression must meet. It also provides contextual typing, so callbacks and literals inside get the right types. |
Errors and edge cases:
- If the value does not match, you get the usual assignability error pointing at the offending property, including excess property checks on object literals.
- With literals,
satisfiescan keep literal types when the target type asks for them (for example a union of string literals). - It does not change runtime output: it compiles to just the expression.
Usage notes
- Annotation vs
satisfiesvsas: annotation checks and widens;satisfieschecks and keeps the inferred type;asoverrides the type without checking assignability the same way. - Pairs well with
as const:{ ... } as const satisfies Tgives readonly literal types that are also validated. The order matters:as constfirst, thensatisfies. - Contextual typing: functions inside the literal receive parameter types from
Type, which saves annotations. - Excess properties are reported for fresh object literals, catching key typos in config objects.
- Exhaustive tables:
satisfies Record<Union, X>ensures every member of a union has an entry. - Version note: added in TypeScript 4.9.
- It is not a runtime check; validate untrusted data with a schema library or guards.