TypeScript Academy · Lesson

Partial and Required: Toggling Optionality

Make all properties optional or required at once.

Lesson 1 of 413 steps

Partial and Required: Toggling Optionality is a free TypeScript Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The TypeScript Academy course includes 4 lessons in total.

Welcome

Partial makes all properties optional. Required makes all properties required. They are the most commonly used utility types for flexible data manipulation.

Partial<T>

Partial makes every property of T optional. Useful for update/patch operations where you don't have all fields.
interface User { id: number; name: string; email: string; }
type PartialUser = Partial<User>;
// { id?: number; name?: string; email?: string; }

Partial in Update Functions

Use Partial when implementing update/merge functions that accept only changed fields.
function updateUser(id: number, changes: Partial<User>): User {
  const existing = findUser(id)!;
  return { ...existing, ...changes };
}

Required<T>

Required removes all optional modifiers, making every property mandatory.
type RequiredUser = Required<User>;
// All properties are now required — including those that were optional

Required for Config Validation

Use Required after merging defaults to ensure all config values are present.
interface Config { host?: string; port?: number; }
const defaults: Required<Config> = { host: 'localhost', port: 3000 };
function createConfig(opts: Config): Required<Config> {
  return { ...defaults, ...opts };
}

How Partial Is Implemented

Partial uses a mapped type with the +? modifier.
type Partial<T> = { [K in keyof T]?: T[K] };
// Equivalent to: { [K in keyof T]+?: T[K] }

How Required Is Implemented

Required uses a mapped type with the -? modifier.
type Required<T> = { [K in keyof T]-?: T[K] };

Deep Partial

The built-in Partial is shallow. For nested objects, you need a recursive DeepPartial.
type DeepPartial<T> = {
  [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K]
};

Combining Partial and Required

Require some fields while keeping others optional using intersection.
// id required, everything else optional
type UpsertUser = Required<Pick<User, 'id'>> & Partial<Omit<User, 'id'>>;

Partial vs Optional Properties in Interface

Declaring all interface properties optional is the same as applying Partial but only for that specific type. Partial is reusable with any type.

Type Inference with Partial

TypeScript correctly narrows Partial properties — accessing them may return T[K] | undefined.
function show(u: Partial<User>) {
  if (u.name !== undefined) {
    console.log(u.name.toUpperCase()); // safe
  }
}

Quick Check

Which utility type makes ALL properties of an interface required, including previously optional ones?

Recap

Partial makes all properties optional (useful for patches/updates). Required makes all properties mandatory (useful for post-merge validation). Both are shallow — use recursive versions for nested types.
Free to start

Learn TypeScript with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
101
Lessons
352

Frequently Asked Questions

Is the “Partial and Required: Toggling Optionality” lesson free?

Yes — the full text of “Partial and Required: Toggling Optionality” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO. The TypeScript Academy course includes 4 lessons in total.

What will I learn in “Partial and Required: Toggling Optionality”?

Make all properties optional or required at once. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “Partial and Required: Toggling Optionality” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Partial and Required: Toggling Optionality
  2. Pick and Omit: Selecting Properties
  3. Record: Mapping Keys to Value Types
  4. Readonly, Exclude, Extract, NonNullable
← Back to TypeScript Academy