TypeScript · Middle · Question 27 of 75

What do -readonly and -? do in a mapped type?

type Mutable<T> = { -readonly [K in keyof T]-?: T[K] };

Explanation

The - prefix removes a modifier, + (the default) adds it. That's how Required<T> is implemented (-?). There's no built-in Mutable, but it's often written following this pattern.

Further reading

Problem with a question

TypeScript · Middle · question 27

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