Recall & Review
beginner
What does the minus (-) modifier do in TypeScript mapped types?
It removes a specific modifier (like readonly or optional) from properties in a mapped type.
Click to reveal answer
beginner
How do you remove the readonly modifier from all properties of a type
T?Use
{ -readonly [P in keyof T]: T[P] } to create a new type without readonly modifiers.Click to reveal answer
intermediate
What is the difference between
+readonly and -readonly in mapped types?+readonly adds the readonly modifier, while -readonly removes it.Click to reveal answer
intermediate
Can you remove the optional modifier from properties in a mapped type? How?
Yes, by using
-? after the property name, like { [P in keyof T]-?: T[P] }.Click to reveal answer
beginner
Example: What does this type do?<br>
type Mutable<T> = { -readonly [P in keyof T]: T[P] }It creates a new type from
T where all properties are mutable (not readonly).Click to reveal answer
Which syntax removes the readonly modifier from properties in a mapped type?
✗ Incorrect
The minus sign before readonly removes the readonly modifier.
How do you remove the optional modifier from properties in a mapped type?
✗ Incorrect
The minus question mark (-?) removes the optional modifier.
What does this mapped type do?<br>
type Readonly<T> = { +readonly [P in keyof T]: T[P] }✗ Incorrect
+readonly adds the readonly modifier to properties.
Which modifier removes the optional flag from a property in a mapped type?
✗ Incorrect
The -? removes the optional modifier from properties.
If you want to make all properties mutable (not readonly), which syntax is correct?
✗ Incorrect
Removing readonly with -readonly makes properties mutable.
Explain how to remove the readonly and optional modifiers from all properties of a TypeScript type using mapped types.
Think about using minus signs before modifiers inside the mapped type.
You got /4 concepts.
Describe the difference between adding and removing modifiers in TypeScript mapped types and give examples.
Focus on the plus and minus signs before modifiers.
You got /4 concepts.