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[]>;

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.

Further reading

Problem with a question

TypeScript · Middle · question 14

Test yourself

Take the TypeScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz