- Home
- Services
- IVY
- Portfolio
- Blogs
- About Us
- Contact Us
- Sun-Tue (9:00 am-7.00 pm)
- infoaploxn@gmail.com
- +91 656 786 53
TypeScript provides powerful utility types to manipulate and transform existing types. Among them, Omit, Pick, Exclude, and Extract are commonly used for type operations. While they may seem similar, each serves a distinct purpose.
In this blog post, we’ll explore:
1. Pick<Type, Keys> – Select Specific Properties
Pick creates a new type by selecting only the specified properties from an existing type.
Syntax:
Pick<Type, "key1" | "key2">
Example
interface User { id: number; name: string; email: string; age: number; } type UserBasicInfo = Pick<User, "name" | "email">; // Equivalent to: { name: string; email: string; }
Use Case:
2. Omit<Type, Keys> – Remove Specific Properties
Omit does the opposite of Pick—it removes specified properties from a type, keeping the rest.
Syntax:
Omit<Type, "key1" | "key2">
Example:
interface User { id: number; name: string; email: string; age: number; } type UserWithoutId = Omit<User, "id">; // Equivalent to: { name: string; email: string; age: number; }
Use Case:
3. Exclude<UnionType, ExcludedMembers> – Filter Union Types
Exclude removes specific members from a union type.
Syntax:
Exclude<UnionType, "value1" | "value2">
Example:
type Status = "pending" | "completed" | "failed";
type NonFailedStatus = Exclude<Status, "failed">;
// Equivalent to: "pending" | "completed"
Use Case:
4. Extract<UnionType, Match> – Keep Matching Union Members
Extract does the opposite of Exclude—it keeps only the matching members from a union.
Syntax:
Extract<UnionType, "value1" | "value2">
Example:
type Status = "pending" | "completed" | "failed";
type OnlyCompleted = Extract<Status, "completed">;
// Equivalent to: "completed"
Use Case:
Object types: Selects specific properties Omit
Object types: Removes specific properties Exclude
Union types: Removes matching members Extract
Union types: Keeps only matching members
Example Combining Them:
type User = { id: number; name: string; role: "admin" | "user" }; type PublicUser = Omit<User, "id"> & { role: Extract<User["role"], "user"> }; // Result: { name: string; role: "user" }
Understanding these utility types helps in:
By mastering Pick, Omit, Exclude, and Extract, you can manipulate TypeScript types more effectively.
Imagine reducing your operational costs by up to $100,000 annually without compromising on the technology you rely on. Through our partnerships with leading cloud and technology providers like AWS (Amazon Web Services), Google Cloud Platform (GCP), Microsoft Azure, and Nvidia Inception, we can help you secure up to $25,000 in credits over two years (subject to approval).
These credits can cover essential server fees and offer additional perks, such as:
By leveraging these credits, you can significantly optimize your operational expenses. Whether you're a startup or a growing business, the savings from these partnerships ranging from $5,000 to $100,000 annually can make a huge difference in scaling your business efficiently.
The approval process requires company registration and meeting specific requirements, but we provide full support to guide you through every step. Start saving on your cloud infrastructure today and unlock the full potential of your business.