Remove a Property from an Object in TypeScript

You’re working with API data or form inputs, and suddenly you need to remove a field before sending it forward. Maybe you want to strip out a password, remove metadata, or clean up unused properties. Sounds simple, but in TypeScript, you also need to think about type safety.

That’s where things get tricky. JavaScript lets you remove properties freely, but TypeScript enforces rules through types, interfaces, and compiler checks.

In this article, I’ll show you 4 ways to remove a property from an object in TypeScript.

Method 1 – Use the delete Operator

This is the most direct way to remove a property. It works best when you already have a mutable object and want to modify it in place.

Step 1: Define the object type

interface User {
id: number;
name: string;
password?: string;
}

How does this code work?
The interface User defines the shape of the object. The password? makes the property optional, which is required when using delete.

Step 2: Remove the property using delete

const user: User = {
id: 1,
name: "John",
password: "secret123"
};

delete user.password;

console.log(user);

Output:

{ id: 1, name: "John" }

You can refer to the screenshot below to see the output.

Remove a Property from an Object TypeScript

How does this code work?
The delete keyword removes the property from the object. TypeScript allows this only because the password is optional.

Pro Tip: Always mark properties as optional (?) when you plan to delete them, or TypeScript will throw an error in strict mode.

Method 2 – Use Object Destructuring (Immutable Way)

Use this method when you want to avoid mutating the original object. This is common in React, Redux, and functional programming.

Step 1: Destructure and exclude the property

const user = {
id: 1,
name: "John",
password: "secret123"
};

const { password, ...safeUser } = user;

console.log(safeUser);

Output:

{ id: 1, name: "John" }

You can refer to the screenshot below to see the output.

Remove a Property from an Object in TypeScript

How does this code work?
The destructuring syntax extracts the password and collects the remaining properties into safeUser using the rest operator (…).

Pro Tip: This is the safest approach for state updates because it avoids side effects and keeps your original object unchanged.

Method 3 – Use Omit Type for Strong Type Safety

Use this when you want TypeScript to enforce that a property is removed at the type level.

Step 1: Define the original type

interface User {
id: number;
name: string;
password: string;
}

Step 2: Create a new type without the property

type SafeUser = Omit<User, "password">;

How does this code work?
The Omit<Type, Keys> utility type removes specified keys from a type. Here, it removes password from User.

Step 3: Create a new object

const user: User = {
id: 1,
name: "John",
password: "secret123"
};

const safeUser: SafeUser = {
id: user.id,
name: user.name
};

console.log(safeUser);

Output:

{ id: 1, name: "John" }

You can refer to the screenshot below to see the output.

Remove Property from an Object TypeScript

How does this code work?
The SafeUser type ensures that the password cannot exist in the new object. The compiler enforces this rule.

Pro Tip: Use Omit in APIs and DTOs (Data Transfer Objects) to prevent accidental data leaks like passwords.

Method 4 – Setting Property to Undefined

This method does not remove the property physically but makes it unusable. It works when deletion is not required, but value removal is enough.

Step 1: Use optional property

interface User {
id: number;
name: string;
password?: string;
}

Step 2: Assign undefined

const user: User = {
id: 1,
name: "John",
password: "secret123"
};

user.password = undefined;

console.log(user);

Output:

{ id: 1, name: "John", password: undefined }

How does this code work?
Instead of removing the key, you assign undefined. The property still exists but has no usable value.

Pro Tip: Use this approach when working with APIs that expect a fixed schema but allow empty values.

Things to Keep in Mind

  • Optional properties required for delete: You cannot use delete on required fields in strict mode.
  • Mutability vs immutability: delete changes the original object, while destructuring creates a new one.
  • Type safety with Omit: Always prefer Omit when shaping API responses or DTOs.
  • undefined vs removal: Setting a property to undefined does not remove it from the object.
  • Strict mode behavior: In strictNullChecks, undefined handling must be explicit to avoid errors.
  • Avoid using any: Using any bypasses type safety and can hide bugs during property removal.

You learned four practical ways to remove a property from an object in TypeScript, from direct deletion to type-safe transformations. Use delete for quick mutations, destructuring for safe updates, and omit when type safety matters most. I hope you found this article helpful.

You may also read:

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.