TypeScript · Middle · Question 14 of 75
What does the satisfies operator do?
const palette = {
red: [255, 0, 0],
green: '#00ff00',
} satisfies Record<string, string | number[]>;- ✓Correct answer: Checks conformance to the type but keeps the more precise inferred type
- 2Casts the value to the given type without checking, like
as - 3Widens the value's type to the given one, losing literal details
Explanation
With the annotation : Record<...>, palette.green would become string | number[]. With satisfies, the shape is checked, but palette.green stays string, so you can call .toUpperCase(). Unlike as, nothing is asserted without a check.