How to Use Typescript Omit with Multiple Properties?

Recently, I was building a TypeScript-based healthcare application where I needed to create different views of the same user data like some for public display, some for internal medical staff, and others for account settings. The issue was that each view required removing a different set of sensitive or internal-use-only properties from a complex interface.

After searching for solutions, I found out that it can be done using the Omnit type property in TypeScript.

In this blog, I’ll explain several ways to use the Omit utility type in TypeScript to exclude multiple properties from interfaces or types, with real-world examples.

What is the Omit Utility Type in TypeScript?

The Omit utility type in TypeScript allows you to create a new type by excluding specific properties from an existing type. It’s incredibly useful when you want to reuse type definitions without certain fields.

The basic syntax is:

type NewType = Omit<OriginalType, 'propertyToRemove'>;

Check out: Conditionally Add Property to Object in TypeScript

Method 1: Using Omit with a Union of Property Names

The most straightforward way to omit multiple properties is to use a union type for the second parameter:

interface Username {
  id: number;
  firstName: string;
  lastName: string;
  email: string;
  password: string;
  role: string;
}

type PublicUser = Omit<Username, 'password' | 'email'>;

const publicUserExample: PublicUser = {
  id: 1,
  firstName: 'Jane',
  lastName: 'Doe',
  role: 'admin'
};
console.log('PublicUser Example:', publicUserExample);

Output:

TypeScript Omit Type

In this example, PublicUser will have all properties from User except password and email. This is perfect for creating public-facing versions of your data models.

Let’s see what the resulting type looks like:

// PublicUser is equivalent to:
interface PublicUser {
  id: number;
  firstName: string;
  lastName: string;
  role: string;
}

Check out: Check if an Object Has a Property in TypeScript

Method 2: Creating a Reusable Omit Type

If you need to omit the same set of properties from multiple types, you can create a custom utility type:

type OmitSensitiveInfo<T> = Omit<T, 'password' | 'email' | 'ssn'>;

interface Employee {
  id: number;
  firstName: string;
  lastName: string;
  email: string;
  password: string;
  ssn: string;
  department: string;
}

interface Customer {
  id: number;
  firstName: string;
  lastName: string;
  email: string;
  password: string;
  ssn: string;
  loyaltyPoints: number;
}

type PublicEmployee = OmitSensitiveInfo<Employee>;
type PublicCustomer = OmitSensitiveInfo<Customer>;

const publicEmployee: PublicEmployee = {
  id: 101,
  firstName: 'John',
  lastName: 'Smith',
  department: 'HR'
};

const publicCustomer: PublicCustomer = {
  id: 202,
  firstName: 'Alice',
  lastName: 'Brown',
  loyaltyPoints: 500
};

console.log('PublicEmployee:', publicEmployee);
console.log('PublicCustomer:', publicCustomer);

Output:

TypeScript Omit Utility type

This approach is especially helpful when you’re working with multiple related types that share common properties you want to omit.

Method 3: Combining Omit with Other Utility Types

You can combine Omit with other utility types for more complex transformations:

interface Product {
  id: string;
  name: string;
  price: number;
  inventory: number;
  category: string;
  description: string;
  isPublished: boolean;
}

// Combine Omit with Pick
type ProductListItem = Omit<Product, 'description' | 'inventory'> & {
  shortDescription: string;
};

type ProductDraft = Omit<Product, 'id' | 'isPublished' | 'category'> & Partial<Pick<Product, 'category'>>;

const productListItem: ProductListItem = {
  id: 'p1',
  name: 'Sunscreen',
  price: 25,
  category: 'Skincare',
  isPublished: true,
  shortDescription: 'SPF 50+ protection'
};

const productDraft: ProductDraft = {
  name: 'Night Cream',
  price: 30,
  inventory: 10,
  description: 'Rich in Vitamin C'
};

console.log('ProductListItem:', productListItem);
console.log('ProductDraft:', productDraft);

Output:

Combine Omit with utility in TypeScript

In the example above, ProductListItem removes some properties but adds a new one, while ProductDraft removes required properties and makes another one optional.

Check out: Remove a Property from an Object in TypeScript

Method 4: Using Omit with String Literal Types

You can also use string literal types to make your code more maintainable:

// Define keys to omit as a type
type UserPrivateFields = 'password' | 'email' | 'ssn';

interface UserProfile {
  id: number;
  username: string;
  firstName: string;
  lastName: string;
  email: string;
  password: string;
  ssn: string;
  bio: string;
}

type PublicProfile = Omit<UserProfile, UserPrivateFields>;

const publicProfile: PublicProfile = {
  id: 7,
  username: 'cooldev',
  firstName: 'Rob',
  lastName: 'Ford',
  bio: 'Frontend Engineer'
};

console.log('PublicProfile:', publicProfile);

Output:

Omit with String Literal Types in TypeScript

This approach makes it easier to manage the list of properties to omit, especially if you need to reference the same set of properties in multiple places.

Check out: Check if an Object Implements an Interface in TypeScript

Method 5: Dynamic Property Omission Using keyof

For more advanced use cases, you can combine keyof with Omit:

interface ApiResponse {
  data: any;
  status: number;
  message: string;
  timestamp: number;
  requestId: string;
  errors: string[];
}

type SuccessResponse<T> = Omit<
  ApiResponse, 
  Extract<keyof ApiResponse, 'errors' | 'message'>
> & { data: T };

const successResponse: SuccessResponse<{ userId: number }> = {
  data: { userId: 123 },
  status: 200,
  timestamp: Date.now(),
  requestId: 'req_abc123'
};

console.log('SuccessResponse:', successResponse);

Output:

Property Omission Using keyof in TypeScript

This example uses Extract with keyof to dynamically determine which properties to omit.

Real-World Example: Building a User Management System

Let’s use these techniques in a practical example. Imagine we’re building a user management system for a healthcare application:

interface MedicalUser {
  id: string;
  firstName: string;
  lastName: string;
  email: string;
  password: string;
  dateOfBirth: string;
  ssn: string;
  medicalHistory: string[];
  insuranceDetails: {
    provider: string;
    policyNumber: string;
    expiryDate: string;
  };
  emergencyContact: {
    name: string;
    relationship: string;
    phone: string;
  };
}

type SensitiveFields = 'password' | 'ssn' | 'medicalHistory';
type MedicalOnlyFields = 'medicalHistory' | 'insuranceDetails';

type PublicUserProfile = Omit<MedicalUser, SensitiveFields | MedicalOnlyFields>;
type MedicalStaffView = Omit<MedicalUser, 'password'>;
type AccountSettings = Omit<MedicalUser, 'medicalHistory' | 'id'>;

const publicUserProfile: PublicUserProfile = {
  id: 'U1001',
  firstName: 'Emily',
  lastName: 'Johnson',
  email: 'emily.johnson@example.com',
  dateOfBirth: '1988-06-15',
  emergencyContact: {
    name: 'Michael Johnson',
    relationship: 'Husband',
    phone: '312-555-6789'
  }
};

const staffView: MedicalStaffView = {
  id: 'U1001',
  firstName: 'Emily',
  lastName: 'Johnson',
  email: 'emily.johnson@example.com',
  dateOfBirth: '1988-06-15',
  ssn: '987-65-4321',
  medicalHistory: ['Diabetes Type 2', 'Hypertension'],
  insuranceDetails: {
    provider: 'Blue Cross Blue Shield',
    policyNumber: 'BCBS-IL-458392',
    expiryDate: '2026-05-01'
  },
  emergencyContact: {
    name: 'Michael Johnson',
    relationship: 'Husband',
    phone: '312-555-6789'
  }
};

const accountSettings: AccountSettings = {
  firstName: 'Emily',
  lastName: 'Johnson',
  email: 'emily.johnson@example.com',
  password: 'securePassword123',
  dateOfBirth: '1988-06-15',
  ssn: '987-65-4321',
  insuranceDetails: {
    provider: 'Blue Cross Blue Shield',
    policyNumber: 'BCBS-IL-458392',
    expiryDate: '2026-05-01'
  },
  emergencyContact: {
    name: 'Michael Johnson',
    relationship: 'Husband',
    phone: '312-555-6789'
  }
};

console.log('PublicUserProfile:', publicUserProfile);
console.log('MedicalStaffView:', staffView);
console.log('AccountSettings:', accountSettings);

Output:

Omit with Multiple Properties in TypeScript

This example shows how you can create different views of the same data model by selectively omitting different combinations of properties.

Check out: Error TS2550: Property ‘includes’ Does Not Exist on Type ‘String’ in TypeScript

Both methods work great – the union approach is simple and direct, while creating custom utility types can make your code more maintainable when you need to reuse the same omissions across multiple types.

Conclusion

In this tutorial, we’ve learned how to use TypeScript’s Omit utility type to exclude multiple properties from interfaces and types. We discussed different methods, from using a union of property names to creating reusable omit types and even combining Omit with other utilities like Pick and Partial.

We also understood omit property using a real-world example of a healthcare user management system to see how Omit helps us create different views of the same data for public profiles, internal staff, and account settings.

.

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.