0
0
Typescriptprogramming~5 mins

Removing modifiers with minus in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A{ [P in keyof T]-?: T[P] }
B{ -readonly [P in keyof T]: T[P] }
C{ readonly [P in keyof T]: T[P] }
D{ +readonly [P in keyof T]: T[P] }
How do you remove the optional modifier from properties in a mapped type?
A{ [P in keyof T]-?: T[P] }
B{ -readonly [P in keyof T]: T[P] }
C{ +readonly [P in keyof T]: T[P] }
D{ [P in keyof T]?: T[P] }
What does this mapped type do?<br>
type Readonly<T> = { +readonly [P in keyof T]: T[P] }
ARemoves optional modifier from all properties
BRemoves readonly modifier from all properties
CAdds readonly modifier to all properties
DAdds optional modifier to all properties
Which modifier removes the optional flag from a property in a mapped type?
A+?
B+readonly
C-readonly
D-?
If you want to make all properties mutable (not readonly), which syntax is correct?
A{ -readonly [P in keyof T]: T[P] }
B{ +readonly [P in keyof T]: T[P] }
C{ [P in keyof T]-?: T[P] }
D{ [P in keyof T]+?: T[P] }
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.