Satisfies operator
Concept and syntax
Use expression satisfies Type to check that an expression fits a contract while retaining its useful inferred type rather than replacing it with the annotation type. Contextual typing can influence that inference. Here a settings object must use an allowed mode and a numeric size, yet its mode remains the literal "light". The operator is erased; it does not validate data at runtime or coerce incompatible values.
Working example
Compile standalone examples in a fresh directory with tsc --strict --target ES2022 --module commonjs --noEmitOnError main.ts, then node main.js.
const settings = { mode: "light", size: 12 } satisfies { mode: "light" | "dark"; size: number };const mode: "light" = settings.mode;settings.size = 14;console.log(mode, settings.size);Expected output (one line per log):
light 14Common mistake
Intentionally invalid; check this snippet separately. Do not run it.
const settings = { mode: "blue", size: 12 } satisfies { mode: "light" | "dark"; size: number };Expected compiler diagnostic: TS2322. Blue is outside the contract. Change it to an allowed value rather than asserting away the mismatch.
Practice and recap
Create a settings object with mode dark and a number size using satisfies. Try an unlisted mode and then correct it.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Satisfies operator — knowledge check
Check the concept, apply it to a new choice, and interpret a compiler diagnostic.
What is the purpose of satisfies?
What happens when a property violates the checked contract?
Which mode satisfies the given contract?
const settings = { mode: "blue", size: 12 } satisfies { mode: "light" | "dark"; size: number };