TypeScript The satisfies Operator
TypeScript 4.9 added a small operator with a big effect: satisfies. It lets you check that a value matches a type without changing the type that TypeScript infers for it. To see why that matters, compare the two older options: annotating a variable and leaving it unannotated.
The dilemma: annotation vs inference
Suppose a palette maps color names to either an RGB tuple or a hex string. With a type annotation, TypeScript validates the object, but the variable's type becomes exactly the annotation — the knowledge of which entry is a string and which is a tuple is lost:
type RGB = [number, number, number];
type Palette = Record<"red" | "green" | "blue", string | RGB>;
const palette: Palette = {
red: [255, 0, 0],
green: "#00ff00",
blue: [0, 0, 255],
};
console.log(palette.green.toUpperCase());main.ts(10,27): error TS2339: Property 'toUpperCase' does not exist on type 'string | RGB'.
Property 'toUpperCase' does not exist on type 'RGB'.
We know green is a string, but its type is string | RGB. Without the annotation, the specific types are kept — but then nothing checks the object, so a typo like bleu or a wrong value slips through.
satisfies gives you both
expression satisfies Type checks the expression against Type (including excess property checks), then keeps the expression's own, more precise inferred type:
type RGB = [number, number, number];
type Palette = Record<"red" | "green" | "blue", string | RGB>;
const palette = {
red: [255, 0, 0],
green: "#00ff00",
blue: [0, 0, 255],
} satisfies Palette;
console.log(palette.green.toUpperCase()); // green: string
console.log(palette.red.map((c) => c / 255)); // red: [number, number, number]#00FF00
[ 1, 0, 0 ]
And mistakes are still caught. Here blue has been misspelled as bleu:
type RGB = [number, number, number];
type Palette = Record<"red" | "green" | "blue", string | RGB>;
const palette = {
red: [255, 0, 0],
green: "#00ff00",
bleu: [0, 0, 255],
} satisfies Palette;
console.log(palette);main.ts(7,3): error TS2353: Object literal may only specify known properties, and 'bleu' does not exist in type 'Palette'.
Comparing the three options
| Code | Checked against the type? | Resulting type |
|---|---|---|
const x = value |
no | inferred from value |
const x: T = value |
yes | T (widened) |
const x = value satisfies T |
yes | inferred from value (narrow) |
const x = value as T |
barely — only rejects impossible casts | T (unsafe) |
Note the difference from as: a type assertion tells the compiler what the type is and suppresses many errors, while satisfies asks the compiler to verify it. satisfies never makes code less safe.
satisfies with as const
The two combine nicely for configuration objects. as const keeps literal values, satisfies validates the shape:
type Route = { path: string; auth: boolean };
const routes = {
home: { path: "/", auth: false },
profile: { path: "/me", auth: true },
admin: { path: "/admin", auth: true },
} as const satisfies Record<string, Route>;
type RouteName = keyof typeof routes; // "home" | "profile" | "admin"
function go(target: RouteName): string {
const r = routes[target];
return r.auth ? `${r.path} (login required)` : r.path;
}
console.log(go("home"));
console.log(go("admin"));/
/admin (login required)
With a plain Record<string, Route> annotation, RouteName would have been just string, and go("adimn") would compile. With satisfies, the keys stay known and the typo would be an error.
Ensuring every case is covered
Another nice use is checking that a lookup table has an entry for every member of a union, while keeping each entry's exact type:
type Level = "low" | "medium" | "high";
const badge = {
low: { text: "Low", color: "green" },
medium: { text: "Medium", color: "orange" },
high: { text: "High", color: "red" },
} satisfies Record<Level, { text: string; color: string }>;
const levels: Level[] = ["high", "low"];
for (const lv of levels) {
console.log(`${badge[lv].text} -> ${badge[lv].color}`);
}High -> red
Low -> green
If you add "critical" to Level later, the badge object immediately reports the missing key.
Tip: A good rule of thumb: use an annotation when you want the wider type (for a variable you'll reassign), and
satisfieswhen you want validation but also the most precise type for a constant.
Test yourself
What does value satisfies T do to the type of the expression?
- Changes it to
T - Keeps the inferred type, after checking it against
T - Changes it to
unknown - Makes it readonly
Which is the safest way to check a config object against a type while keeping its literal keys?
as Config: Configannotationsatisfies Config<Config>prefix
In which TypeScript version did satisfies appear?
- 3.7
- 4.1
- 4.9
- 5.5