Skip to content

Conversation

huggingbot
Copy link
Member

Description

This PR updates the TypeScript documentation with a clearer example of using Omit with conditional types. The new example makes it easier to understand how to conditionally remove properties based on the value of quantity.

Changes

  • Replaced the previous singleItemPayload example with a more precise generic type SingleItemPayload<T>.
  • Improved the explanation and updated the example to show how color is omitted when quantity === 1.

Before

const singleItemPayload = Omit<CartItem, "color" extends string ? "color" : never>;
const cartPayload: singleItemPayload[] = [];

After

type SingleItemPayload<T extends CartItem> = T extends { quantity: 1 }
  ? Omit<T, 'color'>
  : T

const cartPayload: SingleItemPayload<CartItem & { quantity: 1 }>[] = [
  { productId: 123, quantity: 1 },
];

@huggingbot huggingbot requested a review from a team as a code owner February 26, 2025 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants