From 23fd000020dadf7fe06c7ed002775aad395e82fc Mon Sep 17 00:00:00 2001 From: weechien <83656073+huggingbot@users.noreply.github.com> Date: Wed, 26 Feb 2025 12:44:28 +0800 Subject: [PATCH] refactor: Improve TypeScript example for conditional type manipulation --- docs/typescript.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/typescript.md b/docs/typescript.md index 87bd03a5..3666312a 100644 --- a/docs/typescript.md +++ b/docs/typescript.md @@ -928,10 +928,14 @@ interface CartItem { color?: string; // Optional color // Omit color if quantity is 1 -const singleItemPayload = Omit; +type SingleItemPayload = T extends { quantity: 1 } + ? Omit + : 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[] = [ + { productId: 123, quantity: 1 }, +]; ``` ## Interfaces