satisfies
satisfies checks that an expression matches a type without changing the type the compiler inferred for it. You get validation against a contract and the precise literal type of what you actually wrote.
Detailed Explanation
Before TypeScript 4.9 there were two ways to relate a value to a type, and both cost you something.
Annotate it. const theme: Theme = { ... } checks the object against Theme, which is what you wanted. But the variable's type becomes Theme, and everything more specific is thrown away. If Theme is Record<string, string>, then theme.brand is string and theme.brnad is also string, because the index signature accepts any key. Your carefully written literal has been flattened into the shape of the contract.
Assert it. const theme = { ... } as Theme keeps more of the original type, but an assertion does not really check anything — it overrides the checker. A missing property or a typo'd value passes straight through. The annotation was too strict about the result; the assertion is not strict enough about the input.
satisfies is the third option, and it does the sensible thing:
const theme = { brand: "#4f46e5", danger: "#dc2626" } satisfies Record<string, `#${string}`>;
The compiler verifies the object is assignable to Record<string, \#${string}`>, including excess-property checking on the literal. Then it forgets the constraint and gives themethe type it would have inferred anyway:{ brand: "#4f46e5"; danger: "#dc2626" }`. Check with the contract, keep the detail.
This matters most for the objects that describe your application to itself — theme maps, route tables, feature-flag registries, command handlers, environment config. Those objects want two things at once. They want to be validated (every route must have a handler; every colour must be a hex string) and they want to stay specific (Object.keys(routes) should give you the actual route names, not string).
const routes = {
home: "/",
billing: "/settings/billing",
} satisfies Record<string, `/${string}`>;
type RouteName = keyof typeof routes; // "home" | "billing", not string
With an annotation, RouteName would have been string and the union would be useless.
A few behavioural details worth knowing. satisfies is an expression-level operator: it goes after the value, and it is erased at compile time exactly like an annotation. It does not widen, but it also does not narrow — properties of a mutable object literal still widen to string unless you add as const. The combination { ... } as const satisfies Contract is common and does what it reads like: freeze to literal types, then check them against the contract. Finally, satisfies participates in contextual typing, so an array written where the contract expects a tuple is inferred as a tuple.
The cost is close to zero at runtime and small everywhere else: one more keyword for readers to learn, and a hard version floor of TypeScript 4.9. When you want a variable to have exactly the contract type — a function parameter, an exported value with a stable public shape — an annotation is still the right tool.
Code Examples
1. The three options, side by side.
// 1. The three options, side by side.
type Palette = Record<string, string | [number, number, number]>;
const annotated: Palette = { brand: "#4f46e5", accent: [255, 0, 0] };
annotated.brand.toUpperCase();
// Error: Property 'toUpperCase' does not exist on type 'string | [number, number, number]'.
// The annotation widened every value to the union.
const asserted = { brand: "#4f46e5", acccent: [255, 0, 0] } as Palette; // typo passes silently
const checked = { brand: "#4f46e5", accent: [255, 0, 0] } satisfies Palette;
checked.brand.toUpperCase(); // brand is known to be a string
checked.accent[0]; // accent is known to be a tuple of numbers2. Keeping the keys, which is the usual reason to reach for it.
// 2. Keeping the keys, which is the usual reason to reach for it.
const routes = {
home: "/",
billing: "/settings/billing",
} satisfies Record<string, `/${string}`>;
type RouteName = keyof typeof routes; // "home" | "billing"
function go(name: RouteName) {
return routes[name];
}
go("billing");
go("bilingual");
// Error: Argument of type '"bilingual"' is not assignable to parameter of type 'RouteName'.
const broken = { home: "index.html" } satisfies Record<string, `/${string}`>;
// Error: Type '"index.html"' is not assignable to type '`/${string}`'.3. satisfies checks, it does not freeze. Pair it with as const when you need literals.
// 3. satisfies checks, it does not freeze. Pair it with as const when you need literals.
type Flags = Record<string, boolean | { rollout: number }>;
const loose = { newCheckout: { rollout: 25 } } satisfies Flags;
loose.newCheckout.rollout = 50; // still mutable; rollout is number
const frozen = { newCheckout: { rollout: 25 } } as const satisfies Flags;
// frozen.newCheckout.rollout is the literal 25, and the object is readonlyCommon Gotchas
`satisfies` does not make a value readonly
it only checks. Object properties still widen to `string` or `number` unless you also write `as const`, so a map you expected to give literal types may not.
Requires TypeScript 4.9 or newer
older compilers report a syntax error, and so do some editors and build tools pinned to an older `typescript` package. Check the version before adding it to a shared codebase.
Wrong tool for public API surfaces
an exported value checked with `satisfies` exports its full inferred shape, so every literal detail becomes part of your contract and any change is a breaking change. Annotate exports you intend to keep stable.
It does not replace runtime validation
like every type-level construct, `satisfies` is erased. It proves your source literal is well-formed, not that data parsed from a config file is.