← Back to TypeScript Course | Chapter 8: Advanced Types | Lesson 8 of 20

Satisfies Operator

The satisfies operator checks that an expression conforms to a type without changing the expression's inferred type. It is useful when you want validation while preserving precise literal information.
Syntax
typescript
const variable = {
  property: value,
} satisfies TypeName;

Basic satisfies Usage

The satisfies operator checks that an expression conforms to a required type without changing the type TypeScript actually infers for that expression — you get validation and precise inference at the same time.

Example: Basic satisfies Usage

typescript
type Config = { port: number; host: string };
const config = { port: 8080, host: "localhost" } satisfies Config;
console.log(config.port);

Preserving Literal Information

Unlike a broad type annotation, satisfies preserves specific literal information from the original expression, so a value checked with satisfies keeps its narrow, literal type instead of being widened to the annotation's type.

Example: Preserving Literal Information

typescript
type Colors = Record<string, string>;
const palette = { red: "#ff0000", green: "#00ff00" } satisfies Colors;
console.log(palette.red.toUpperCase());

Checking Object Keys

satisfies is particularly useful for record objects where you want TypeScript to catch missing or misspelled keys against a required shape, without losing the ability to access each key's specific value type afterward.

Example: Checking Object Keys

typescript
type Routes = Record<"home" | "about", string>;
const routes = { home: "/", about: "/about" } satisfies Routes;
console.log(routes.about);

satisfies with Functions

A function-valued property can be checked with satisfies while the expression itself stays directly callable and usable exactly as written, unlike casting it with an explicit type annotation would.

Example: satisfies with Functions

typescript
type Handlers = Record<string, (x: number) => number>;
const handlers = {
  double: (x: number) => x * 2,
} satisfies Handlers;
console.log(handlers.double(5));

satisfies vs Type Annotation

A type annotation tells TypeScript to treat a value as the declared type going forward, while satisfies only checks compatibility once and then lets the expression keep its own more specific inferred type.

Example: satisfies vs Type Annotation

typescript
type Config = { port: number };
const annotated: Config = { port: 8080 };
const satisfied = { port: 8080 } satisfies Config;
console.log(annotated.port, satisfied.port);
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Using satisfies and expecting the variable to have the wide type, when it keeps the narrower inferred type.
  2. Writing satisfies where an annotation is needed, so the variable is no longer typed as the interface for later assignment.
  3. Expecting satisfies to allow extra misspelled keys, when it reports excess properties on an object literal.

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.