intermediate
satisfies operator
Validate object shape against a target type while preserving narrow inferred literal information.
The `satisfies` operator checks that an expression conforms to a target type while preserving the expression's inferred type. It helps configuration objects, route maps, theme tokens, and lookup tables where you want validation without losing literal detail.
const routes = {
api: { path: '/v1' },
admin: { path: '/admin' },
} satisfies Record<string, { path: string }>;
Compare with annotation (may widen), assertion (unsafe), and `as const` (no external shape check). `satisfies` does not change runtime behavior.
On interviews: explain with a concrete example and name what interviewers probe in production code.
Common pitfalls: mixing similar APIs and forgetting edge cases during live coding.
The trade-off is often clarity versus safety or expressiveness versus maintainability. Checklist:
- Use for config objects.
- Preserve literals.
- Remember compile-time only.