TypeScript Course
TypeScript
/
Intermediate

Partial<T>

Definition

A built-in utility type that constructs a new type where all properties of the given Type `T` are set to optional.

Explain Like I'm New

Imagine an application form with 20 required fields. `Partial` takes a photocopy of that form, crosses out the word 'Required' next to every single field, and writes 'Optional'.

Real World Example

Updating a user profile via a PATCH request. You don't want to send the entire `User` object (with ID, email, password) just to update their username. You type the payload as `Partial<User>`.

Common Use Cases

  • •API PATCH requests
  • •React `setState` (merging partial state)
  • •Mocking data in Unit Tests

Interactive Example

Loading Code Playground...

Interview Questions

basic

  • What does `Partial` do to required properties?

intermediate

  • Does `Partial` make deeply nested properties optional?

Flash Cards

Question

Does it make deeply nested properties optional?

Click to reveal answer
Answer

No! `Partial` is shallow. It only makes the top-level keys optional. If your object has `{ config: { theme: string } }`, `config` becomes optional, but if you DO provide `config`, you MUST provide `theme`. Deep partials require a custom recursive mapped type.