How do you remove readonly or optional from every property using mapped type modifiers?
Prefix the modifier with a minus sign inside a mapped type: -readonly removes readonly and -? removes optionality. A plus sign, or none, adds it. Required<T> is exactly { [K in keyof T]-?: T[K] }.
Explain it simply
Modifiers like readonly and ? are switches on each property. In a mapped type you can switch them on with + (or nothing) and off with -.
This is how the built-in Required removes every question mark, and how you can write a Mutable type to undo Readonly on a type you do not own.
Example
interface Config {
readonly host: string;
port?: number;
}
type Mutable<T> = { -readonly [K in keyof T]: T[K] };
type Full<T> = { [K in keyof T]-?: T[K] };
type EditableConfig = Mutable<Config>;
// { host: string; port?: number }
type CompleteConfig = Full<Config>;
// { readonly host: string; port: number }
const c: EditableConfig = { host: "localhost" };
c.host = "example.com"; // OK now
// Both at once
type Strict<T> = { -readonly [K in keyof T]-?: T[K] };What to say in the interview
"In a mapped type, -? strips optionality and -readonly strips readonly, while + or nothing adds them. Required is defined with -?. I would write a Mutable helper this way when I need to modify a type from a library that marks everything readonly."