TypeScript 7 reference · Type Operators and Keywords

TypeScript satisfies Keyword

Check that a value matches a type without widening it, so you keep the exact inferred type and still get errors.

TypeScript 7 Since 4.9

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

expression satisfies Type

Examples

Validate without losing precisionTry it yourself
type Colors = Record<string, string | [number, number, number]>;
const palette = {
  primary: "#0f766e",
  accent: [255, 99, 71],
} satisfies Colors;
// The exact types are kept: primary is a string, accent a tuple
console.log(palette.primary.toUpperCase(), palette.accent[0]);

Output

#0F766E 255
Exact keys plus a shape checkTry it yourself
interface Route {
  path: string;
  auth: boolean;
}
const routes = {
  home: { path: "/", auth: false },
  admin: { path: "/admin", auth: true },
} satisfies Record<string, Route>;
console.log(Object.keys(routes));
// @ts-expect-error: typos in keys are caught because the keys stay exact
console.log(routes.admn);

Output

[ 'home', 'admin' ]
undefined

Version history

VersionChange
TypeScript 4.9Added

Was this page helpful?