mirror of
https://github.com/vercel/commerce.git
synced 2025-06-15 03:41:21 +00:00
Fix: Explicit undefined check for genericProducts[0] in getCollectionProducts
Resolves a persistent TypeScript type error in `lib/shopify/index.ts` within the dummy data logic for the `getCollectionProducts` function: "Type 'Product | undefined' is not assignable to type 'Product'." The error occurred when attempting to use `genericProducts[0]` to populate `dummyCollectionProductsList`. Previous guards like checking `genericProducts.length > 0` were insufficient in the Vercel build environment's TypeScript context. This commit implements a more explicit check: 1. `genericProducts[0]` is assigned to `firstProduct` (typed Product | undefined). 2. `firstProduct` is then checked for `!== undefined` before being used. 3. If `firstProduct` is not undefined, it's safely used to create the `dummyCollectionProductsList`. Otherwise, an empty array is assigned. This more explicit narrowing of the type should satisfy TypeScript's strict checks in all environments.
This commit is contained in:
parent
1e1eeb3b37
commit
dd0962ac28