Question presented to candidate:
"What does the satisfies operator do in TypeScript? How is const x = value satisfies T different from const x: T = value and from value as T?"
What a strong answer should cover:
expr satisfies Tchecks that the expression is assignable toT(including excess-property and missing-property checks) but the expression keeps its own inferred type- Compared with an annotation: both check, but the annotation replaces the type with
T, losing per-property detail (astring | RGBvalue stays a union) - Compared with
as: an assertion barely checks (a missing key slips through),satisfiesreports the error at the offending property - It provides a contextual type, so callback parameters inside the object are typed and tuple targets produce tuples
- It is an expression operator: usable in returns, arguments and exports, not only on variable declarations; it is erased from the JavaScript
- Introduced in TypeScript 4.9 (November 2022)
Code / implementation expected: Yes β the same object written with an annotation, with as, and with satisfies, showing one compile error each would or would not catch.