expr satisfies Type (TS 4.9+) checks that an expression conforms to a type without changing the expression's inferred type. Compare that with a type annotation (const x: Type = …), which widens the variable to Type and loses specific information, and a type assertion (as Type), which skips checking and can lie. satisfies gives you validation plus precise inference: literal keys, specific value types, and excess-property errors, all at once.
type Color = string | [number, number, number];
type Palette = Record<'primary' | 'secondary' | 'accent', Color>;
// Annotation: validated, but every value is now `Color`
const p1: Palette = { primary: '#0af', secondary: [0, 128, 255], accent: '#f60' };
p1.primary.toUpperCase(); // error: Color might be a tuple
// Assertion: no real checking, so missing keys slip through
const p2 = { primary: '#0af' } as Palette; // compiles, but secondary and accent are undefined at runtime
// satisfies: checked AND precise
const p3 = {
primary: '#0af',
secondary: [0, 128, 255],
accent: '#f60',
} satisfies Palette;
p3.primary.toUpperCase(); // OK: string
p3.secondary[0].toFixed(); // OK: number tuple
With satisfies, a missing key, an unknown key (excess property check) or a wrong value type is a compile error, but the variable keeps its literal-ish inferred type.
Config objects with known keys
const routes = {
home: '/',
user: '/users/:id',
} satisfies Record<string, `/${string}`>;
type RouteName = keyof typeof routes; // 'home' | 'user' (an annotation would give `string`)
With as const for literal, readonly data
const themes = ['light', 'dark'] as const satisfies readonly string[];
type Theme = (typeof themes)[number]; // 'light' | 'dark'
Exhaustive maps
type Status = 'idle' | 'loading' | 'error';
const statusLabel = {
idle: 'Waiting',
loading: 'Loading…',
error: 'Failed',
} satisfies Record<Status, string>; // adding a Status forces adding a label
Exhaustiveness in switches: default: value satisfies never.
Framework configs: export default { … } satisfies Config gives editor completion and checking without losing inference.
| Goal | Use |
|---|---|
| The variable's type should be the declared contract (e.g. it may later hold other values) | Annotation : T |
| Validate shape but keep precise inferred types | satisfies T |
| You know better than the compiler (rare, e.g. DOM APIs) | as T (prefer narrowing) |
satisfies doesn't change the type, so if you want widening (a mutable variable you'll reassign to other Colors), use an annotation.satisfies can influence inference of literals (e.g. tuples vs arrays) because the target type provides context.satisfies validates and preserves inference.as.Record maps, as const satisfies.Spotted a mistake or a rights concern? Report an issue