Modifiers in Mapped Types: readonly and ?
Add or remove modifiers with +/- in mapped types.
Welcome
Mapped types can add or remove `readonly` and optional (`?`) modifiers from properties using the `+` and `-` prefixes.
Adding Modifiers with +
The `+` prefix (implicit by default) adds a modifier to each property in the mapped type.
type Readonly<T> = { +readonly [K in keyof T]: T[K] }; // + is implicit
type Optional<T> = { [K in keyof T]+?: T[K] };All lessons in this course
- Mapped Types: Transforming Object Types
- Modifiers in Mapped Types: readonly and ?
- Template Literal Types: String Patterns
- Key Remapping with as in Mapped Types