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

Making All Properties Required

Using -? to remove optionality and create a Required-like mapped type.

Making All Properties Required

What you'll learn: How to use the -? modifier in mapped types to remove optionality and create your own Required-like type.


In the previous lesson, you learned how to make properties optional with +?. Now you'll learn the reverse: how to make all properties required, even if they started out optional.

The -? Modifier

The -? modifier removes optionality from properties. It's the opposite of +?:

type MakeRequired<T> = {
  [K in keyof T]-?: T[K];
};

This mapped type iterates over every key K in T and strips away the optional marker, making each property required.

Seeing It In Action

type User = {
  name?: string;
  age?: number;
  email?: string;
};

type CompleteUser = MakeRequired<User>;
// Result: { name: string; age: number; email: string; }

const user: CompleteUser = {
  name: "Alice",
  age: 30,
  email: "alice@example.com"
};

// Error: Property 'email' is missing
const incomplete: CompleteUser = {
  name: "Bob",
  age: 25
};

Every property becomes mandatory. TypeScript won't let you omit any of them.

How It Relates to the Built-In Required<T>

TypeScript's standard library includes a Required<T> utility type that works exactly this way. Your MakeRequired<T> is essentially a reimplementation to understand the mechanism behind it.

When This Is Useful

  • Validation results where partial input becomes complete output
  • Configuration merging where defaults fill in all optional fields
  • Database entities after creation, when all fields must exist

Key Takeaway: The -? modifier strips optionality from properties in a mapped type, turning optional fields into required ones—exactly how Required<T> works under the hood.