Course contentsShow
← TypeScript
Lesson 751 of 1,79617. Mapped TypesFree lesson

Preserving vs Overriding: When to Use +

Explicitly use + modifiers when you want to add modifiers regardless of source type state.

Preserving vs Overriding: When to Use +

What you'll learn: When to explicitly add the + modifier to ensure properties become readonly or optional, regardless of their original state.

The Default Preservation Behavior

By now you've seen that mapped types preserve existing modifiers unless you tell them otherwise. If a property is already readonly, it stays readonly. If it's optional, it stays optional. This preservation happens silently — it's the default.

But what if you want to guarantee that properties become readonly or optional, whether they started that way or not?

When to Use the + Modifier Explicitly

The + modifier means "add this modifier" — it doesn't just preserve, it ensures the modifier exists. Think of it like a light switch: preservation checks the current state, but + flips it to "on" regardless of where it started.

Adding readonly with +

type MakeReadonly<T> = {
  +readonly [K in keyof T]: T[K];
};

type Person = {
  name: string;
  readonly id: number;
};

type ReadonlyPerson = MakeReadonly<Person>;
// Result: { readonly name: string; readonly id: number; }

Notice both name (which wasn't readonly) and id (which already was) are now readonly. The + forced the issue.

Adding Optional with +

type MakeOptional<T> = {
  [K in keyof T]+?: T[K];
};

type Config = {
  host: string;
  port?: number;
};

type PartialConfig = MakeOptional<Config>;
// Result: { host?: string; port?: number; }

Both host and port are now optional, even though host wasn't before.

When Preservation Is Enough

If you're just transforming property types and don't care about modifiers, omit the +:

type Stringify<T> = {
  [K in keyof T]: string;
};

This transforms values but leaves modifiers alone — simple and clean.

When to Choose +

Use + when you're building utilities that must enforce a modifier state for safety or correctness, like Readonly<T> or Partial<T>. Without the +, you'd only preserve what was already there — which might not be enough.

Key Takeaway: Use + when you need to add modifiers unconditionally, guaranteeing they exist regardless of the source type's state. Omit it when you only want to transform types and preserve existing modifiers naturally.