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
Syntax
expression satisfies Type
Examples
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
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
| Version | Change |
|---|---|
| TypeScript 4.9 | Added |
Related
as const· Make a value deeply read-only with literal types: strings stay 'admin' instead of string, arrays become readonly tuples.typeof (type query)· In a type position, typeof takes the type of a value or function, so you don't have to write it twice.- TypeScript keyof, typeof and Indexed Access · tutorial