Skip to content

Typescript Utility Types: Partial

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

It’s particularly useful when you want to create an object that matches a certain interface or type, but you don’t want to provide all the properties.

Example

interface User {
  name: string;
  age: number;
  address: string;
}

// Make all properties optional using Partial
type PartialUser = Partial<User>;

// Create a PartialUser object
const user: PartialUser = {
  name: 'John Doe',
  // age and address are optional, so they can be omitted
};

console.log(user) // { "name": "John Doe" }