TypeScriptUnions and narrowing
satisfies
Checks that a value matches a type without changing the inferred type.
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 TypeMore examples
#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
satisfieswithas const:{ … } as const satisfies Config. - Choose an annotation when you want the variable to have a general type, and
satisfieswhen the exact types of the values matter to you.
Related entries
#- as vs satisfiesas tells the compiler to trust your type and check nothing, while satisfies checks that the value matches the type and keeps the exact type inferred from the value.
- as constFreezes literals in an expression: the narrowest types and read-only fields.
- Type assertion (as)Telling the compiler the type of a value when you know more than it does.
- Record<Keys, Type>Creates an object type with given keys, where every value has the same type.
- Type inferenceThe compiler figuring out types automatically, without you writing annotations.
Spotted a mistake or missing an example? Write to us.