satisfies

Checks that a value matches a type without changing the inferred type.

On this page

Example

#
TypeScript
type Palette = Record<string, string | [number, number, number]>

const colors = {
  accent: '#a78bfa',
  success: [16, 185, 129]
} satisfies Palette

console.log(colors.accent.toUpperCase())
console.log(colors.success.join(', '))
Result
#A78BFA
16, 185, 129

Definition and usage

#

The satisfies operator verifies that an expression is compatible with the given type, but keeps the exact type inferred from the value itself. That’s what sets it apart from an annotation (const x: T = ...), which “widens” the type to T.

This gives you two benefits at once: the compiler reports a typo or a missing field, and it also remembers the specific literals and keys of the object, so later suggestions stay precise.

It’s most often used with configuration objects and with maps of colors, routes, or translations, where you want a shape check and detailed types preserved.

Syntax

#
Syntax
const value = expression satisfies Type

More examples

#
An annotation loses detail
TypeScript
const annotated: Palette = { accent: '#a78bfa' }
annotated.accent.toUpperCase()
// Error: Property 'toUpperCase' does not exist on type 'string | [number, number, number]'.

Good practices

#
  • With configuration objects, combine satisfies with as const: { … } as const satisfies Config.
  • Choose an annotation when you want the variable to have a general type, and satisfies when the exact types of the values matter to you.

Related entries

#

Spotted a mistake or missing an example? Write to us.