Q21. What is the satisfies operator?
satisfies checks that an expression conforms to a target type while preserving the expression's specific inferred type. It is useful for configuration objects where you want validation without widening every literal. It does not validate runtime data.
A route map can satisfy Record<RouteName, string> while keeping each route path as a string literal.
Note
Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.
TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
- Explain the concept in your own words.
- Know the practical trade-off and its limits.
- Use a small example to demonstrate the idea.
Knowledge Check
What is a key benefit of satisfies?