What is the satisfies Operator in TypeScript?
Master the TypeScript satisfies operator (4.9+): validate values against a type without widening, keep literal inference, and how it beats annotations.
Expected Interview Answer
The satisfies operator, introduced in TypeScript 4.9, checks that an expression matches a target type without changing (widening) the expression's inferred type.
A type annotation forces a variable to the declared type, discarding the narrower literal information the compiler inferred. satisfies instead validates conformance while preserving the precise inferred type, so you still get literal-level autocomplete and narrowing on the value. It is ideal for config objects and constant maps where you want the shape validated but also want to keep exact keys and literal member types. It performs no runtime work — it is a pure compile-time check.
- Validates a value against a type without widening it
- Preserves literal and exact-key inference
- Keeps precise autocomplete on the value
- Catches missing or misspelled keys early
- Zero runtime overhead
AI Mentor Explanation
It is like a selector confirming a player meets every squad-eligibility rule while still recording their exact specialism — 'left-arm wrist spinner', not just 'bowler'. The eligibility is verified, yet the precise role is preserved for team tactics. satisfies checks the type contract but keeps the value's exact inferred details.
Step-by-Step Explanation
Step 1
Write the expression
Author the object or value with its natural literal shape, e.g. a config map.
Step 2
Append satisfies TargetType
Add 'satisfies SomeType' after the expression to validate it against the type.
Step 3
Compiler validates conformance
Missing keys, extra keys, or wrong value types are reported as errors immediately.
Step 4
Inferred type is preserved
Unlike an annotation, the variable keeps its exact literal type for later narrowing.
Step 5
Use the precise type downstream
Enjoy literal autocomplete and exact-key access that a widening annotation would lose.
What Interviewer Expects
- Knows satisfies validates without widening the type
- Contrasts it with a plain type annotation
- Explains preserved literal and key inference
- Gives a config-object use case
- Notes it is compile-time only, TS 4.9+
Common Mistakes
- Thinking satisfies changes the variable's type like an annotation
- Believing it has runtime behavior
- Confusing it with the as type assertion
- Assuming it can force an unsafe cast
Best Answer (HR Friendly)
“The satisfies operator lets you check that a value fits a required type while still keeping all its exact details. Unlike a normal type label, it validates the shape without throwing away the precise information TypeScript figured out, giving you both safety and accuracy.”
Code Example
type Config = Record<string, string | number>
// Annotation widens: 'port' is string | number
const a: Config = { host: 'localhost', port: 8080 }
// a.port.toFixed(0) // Error — could be string
// satisfies validates but preserves literals
const b = {
host: 'localhost',
port: 8080,
} satisfies Config
b.port.toFixed(0) // OK — 'port' is inferred as number
const h: 'localhost' = b.host // exact literal preserved
// Catches mistakes too:
// const c = { host: 'x', prot: 80 } satisfies Config // valid keys, but
// misspelled required keys are caught when the type demands themFollow-up Questions
- How does satisfies differ from a type annotation?
- How does satisfies differ from the as assertion?
- Why does satisfies preserve literal types?
- What version of TypeScript introduced satisfies?
- When would you combine satisfies with as const?
MCQ Practice
1. What is the main advantage of satisfies over a type annotation?
satisfies checks conformance while preserving the precise inferred type, unlike an annotation which widens the value.
2. Which TypeScript version introduced the satisfies operator?
The satisfies operator was added in TypeScript 4.9.
3. How much runtime overhead does satisfies add?
satisfies is erased during compilation and produces no runtime code.
Flash Cards
What does satisfies do? — Validates an expression against a type without widening its inferred type.
satisfies vs annotation — An annotation widens to the declared type; satisfies keeps the exact inferred type while validating.
When was satisfies added? — TypeScript 4.9.
Runtime cost of satisfies — None — it is a compile-time-only check.
Typical use case — Config objects and constant maps where you want validation plus exact-key and literal inference.