Typescript Foundations / Utility Types

Partial

🧩 Partial<T>

Partial<T> is a built-in utility type that makes all properties of a type optional.

It is especially useful when you want to update only a few properties of an existing object instead of providing the entire object.

🔹 Example

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

function updateUser(updates: Partial<User>) {
  console.log(updates);
}

updateUser({
  name: "Bhaskar"
}); // ✅

updateUser({
  age: 25,
  email: "bhaskar@example.com"
}); // ✅

Normally, User requires all three properties:

const user: User = {
  name: "Bhaskar",
  age: 25,
  email: "bhaskar@example.com"
};

But Partial<User> changes it to:

{
  name?: string;
  age?: number;
  email?: string;
}

So you can provide any combination of the properties.

💡 Common Use

Partial is commonly used for update functions, such as updating a user's profile, product details, or application settings.

Remember: Partial<T> → Makes every property in T optional.