Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions docs/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -928,10 +928,14 @@ interface CartItem {
color?: string; // Optional color

// Omit color if quantity is 1
const singleItemPayload = Omit<CartItem, "color" extends string ? "color" : never>;
type SingleItemPayload<T extends CartItem> = T extends { quantity: 1 }
? Omit<T, 'color'>
: T

// Omit color for all items if quantity is always 1
const cartPayload: singleItemPayload[] = [];
// Omit color for all items when quantity is 1
const cartPayload: SingleItemPayload<CartItem & { quantity: 1 }>[] = [
{ productId: 123, quantity: 1 },
];
```

## Interfaces
Expand Down