Removing readonly with Minus
What you'll learn: How to use the minus modifier (-readonly) in mapped types to strip readonly from properties and create mutable versions of immutable types.
The Problem: Undoing Readonly
You've learned how to add readonly to all properties with a mapped type. But sometimes you need the opposite: taking a type that has readonly properties and creating a version where those properties can be modified.
This is where the minus modifier comes in.
The -readonly Syntax
Just as you can add readonly in a mapped type, you can remove it using the minus sign:
type Mutable<T> = {
-readonly [K in keyof T]: T[K]
}
type ReadonlyPerson = {
readonly name: string
readonly age: number
}
type MutablePerson = Mutable<ReadonlyPerson>
// Result: { name: string; age: number }
The -readonly prefix explicitly strips the readonly modifier from every property.
Why This Matters
Sometimes you receive data structures that are intentionally immutable, but you need to work with a mutable copy internally—for example, during data transformations or when building objects step-by-step.
The minus modifier gives you precise control over mutability at the type level.
Comparison to Adding Readonly
Adding readonly: readonly [K in keyof T]
Removing readonly: -readonly [K in keyof T]
Both modifiers operate at the mapped type level, transforming every property systematically.
Key Takeaway: The -readonly modifier in mapped types removes readonly constraints, creating mutable versions of otherwise immutable types—giving you the inverse of readonly mapping.