How to Exclude Property from Type in TypeScript ?
Last Updated :
24 Apr, 2025
In Typescript, sometimes we need to exclude a property from a type when we want a similar type with some properties excluded or if we want to remove a property from the type.
There are several approaches to exclude properties from a type in typescript:
Approach 1: Using Mapped Types with conditional Types
In this approach, we create a new type by iterating the properties of the original type and conditionally excluding certain properties based on a type predicate.
Example: Here, we define a FullType interface with three properties. We then use the ExcludeProps type to create a new type called ExcludedType by excluding the 'prop2' property from FullType. Finally, we create an object of type ExcludedType called test.
JavaScript
type FullType = {
prop1: number;
prop2: string;
prop3: boolean;
};
type ExcludedType = ExcludeProps<FullType, 'prop2'>;
const test: ExcludedType = {
prop1: 123,
prop3: true,
};
console.log(test);
Output:

Approach 2: Using Pick and Omit Utility Types
In this approach we use TypeScript's "Pick" and "Omit" utility types to explicitly include or exclude properties from a type.
Example: Here, we use "Omit" utility type to remove specified properties from the original type which excludes the property.
Similar to Approach 1, we create an ExcludedType by omitting the 'prop2' property from FullType using the Omit utility type.
JavaScript
type FullType = {
prop1: number;
prop2: string;
prop3: boolean;
};
type ExcludedType = Omit<FullType, 'prop2'>;
const test: ExcludedType = {
prop1: 123,
prop3: true,
};
console.log(test);
Output:

Approach 3: Using Intersection Types with Mapped Types
In this approach we intersect the original type with a mapped type that excludes the properties as we instruct.
Example: Here, we used a technique to create a new type by combining an existing type (FullType in this case) with a mapped type that excludes certain properties. Here, ExcludedType is defined as a type that includes all properties from FullType except for 'prop2'. The test variable is declared to be of type ExcludedType. When initializing test, notice that 'prop2' is not included, but other properties like 'prop1' and 'prop3' are allowed.
JavaScript
type FullType = {
prop1: number;
prop2: string;
prop3: boolean;
};
type ExcludedType = FullType & { [K in 'prop2']?: never };
const test: ExcludedType = {
prop1: 123,
prop3: true,
};
console.log(test);
Output:

Approach 4: Using a Custom Type Guard Function
In this approach we define a custom type guard function that checks if a property should be excluded and then a new type is created using a conditional type.
The function excludeProp takes an object obj and a property prop, and it returns a new object omitting that property. The Omit utility type is used to create a new type by excluding the specified property from the original type.
Example: Here, 'type ExcludedType = Omit<FullType, 'prop2'>' ; : This defines a type ExcludedType by omitting 'prop2' from FullType. 'const test: ExcludedType = excludeProp(fullObj, 'prop2');' : Here, test is declared to be of type ExcludedType, which means it doesn't include 'prop2'. The excludeProp function is called with fullObj (an object of type FullType) and 'prop2' as arguments. This will return a new object with 'prop2' excluded.
JavaScript
type FullType = {
prop1: number;
prop2: string;
prop3: boolean;
};
type ExcludedType = Omit<FullType, 'prop2'>;
const test: ExcludedType = excludeProp(fullObj, 'prop2');
console.log(test);
Output:

Approach 5: Using Exclude and Pick Utility Types
In this approach we utilize Typescript's Exclude and Pick utility types to include or exclude properties based on their type.
The Exclude utility type is used to remove properties which the exclusion criteria. The Extract utility type retains properties which matches the inclusion criteria.
Example: Here, 'Exclude<keyof FullType, 'prop2'>:' This part uses the Exclude utility type to remove properties matching the exclusion criteria. keyof FullType retrieves all the keys of the FullType type, and 'prop2' specifies the property to be excluded. 'Pick<FullType, ...>; ' : This part uses the Pick utility type to selectively include properties from FullType. The second argument specifies which properties to include after exclusion, based on the result of the Exclude operation.
JavaScript
type FullType = {
prop1: number;
prop2: string;
prop3: boolean;
};
type ExcludedType = Pick<FullType, Exclude<keyof FullType, 'prop2'>>;
const test: ExcludedType = {
prop1: 123,
prop3: true,
};
console.log(test);
Output:

Similar Reads
How to use property decorators in TypeScript ?
Decorators are a way of wrapping an existing piece of code with desired values and functionality to create a new modified version of it. Currently, it is supported only for a class and its components as mentioned below: Class itselfClass MethodClass PropertyObject Accessor ( Getter And Setter ) Of C
4 min read
How to declare nullable type in TypeScript ?
In vanilla JavaScript, there are two primary data types: null and undefined. While TypeScript previously did not allow explicit naming of these types, you can now use them regardless of the type-checking mode. To assign undefined to any property, you need to turn off the --strictNullChecks flag. How
2 min read
How to map Enum/Tuple to Object in TypeScript ?
Mapping enum or tuple values to objects is a common practice in TypeScript for handling different data representations. This article explores various methods to map enumerations (enums) and tuples to objects, providing examples to illustrate each method.Table of ContentManually mapping Enum to Objec
3 min read
How to Create Deep Readonly Type in Typescript?
In TypeScript, the readonly access modifier is a powerful tool that ensures immutability by marking properties of a class as immutable. Once a property is markedreadonly, it cannot be reassigned. This is highly useful for maintaining consistent and safe data structures, especially in scenarios such
3 min read
How to Check Types in Typescript?
Checking types in TypeScript involves methods like typeof for primitive types, instanceof for class instances, and custom type guards for complex type validation. These techniques help ensure variables are correctly typed, improving code safety, and readability, and preventing runtime errors.Here ar
3 min read
How to check interface type in TypeScript ?
Typescript is a pure object-oriented programming language that consists of classes, interfaces, inheritance, etc. It is strict and it statically typed like Java. Interfaces are used to define contacts in typescript. In general, it defines the specifications of an entity. Below is an example of an in
2 min read
How To Get Types From Arrays in TypeScript?
In TypeScript, arrays are a common data structure, but sometimes it's necessary to extract the types of elements stored in an array for type-checking or validation purposes. TypeScript provides several ways to extract types from arrays, enabling more type-safe operations.We will explore different me
3 min read
How to Remove Focus from Input Field in TypeScript ?
Removing the focus from an input field is a common requirement in web development. This can be useful in scenarios like form validation, user interactions, or controlling focus behavior. The below approaches can be used to achieve this task in TypeScript:Table of Content Using the blur() methodSetti
3 min read
TypeScript in operator narrowing Type
In this article, we will learn about the 'in' operator narrowing Type in Typescript. In TypeScript, the 'in' operator is used to narrow or refine the type of an object within a conditional statement or block. It checks whether a specific property or key exists within an object, and if it does, it na
3 min read
How to Return a Union Type in TypeScript ?
In TypeScript, a union type is a powerful way to express a variable that can be one of several types. Union types are used when a function or variable is expected to support multiple types of input. Union types are defined using the pipe (|) symbol between two or more types. This indicates that a va
4 min read