Interview Q&A / TypeScript

IntermediateQuick answer1 min readUpdated 3 Oct 2026

How do you remove readonly or optional from every property using mapped type modifiers?

SHORT ANSWER

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

ts
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."

#mapped-types#modifiers

Related questions

Practise more TypeScript questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open TypeScript quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.