Dhananjay Patel Logo
  1. Home
  2. / Blog
  3. / Typescript Api
  4. / Lessons
  5. / 2

Partial

  • Partial makes all properties of a type optional, creating a type with the same properties but each marked as optional.
  • Useful when updating or modifying parts of an object.
interface User {
id: string;
name: string;
age: number;
email: string;
password: string;
}
type UpdateUserProps = Partial<Pick<User, 'name' | 'age' | 'email'>>;
function updateUser(updatedProps: UpdateUserProps) {
// Update user in the database
console.log('Updated user:', updatedProps);
}
updateUser({ name: 'Jane Doe', age: 30 });