-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the types for useOptimisticCart()
#2269
Conversation
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
@@ -26,7 +26,7 @@ export function CartMain({layout, cart: originalCart}: CartMainProps) { | |||
cart && | |||
Boolean(cart?.discountCodes?.filter((code) => code.applicable)?.length); | |||
const className = `cart-main ${withDiscount ? 'with-discount' : ''}`; | |||
const cartHasItems = !!cart && cart.totalQuantity > 0; | |||
const cartHasItems = cart?.totalQuantity && cart.totalQuantity > 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rely on the gt operator to narrow the type to boolean
instead of boolean | number | undefined
?
const cartHasItems = cart?.totalQuantity && cart.totalQuantity > 0; | |
const cartHasItems = cart?.totalQuantity > 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typescript doesn't like undefined > 0
. So it has to be cart?.totalQuantity! > 0
2bf295e
to
0fdf276
Compare
* Improve the types for `useOptimisticCart()` * Fixes
WHY are these changes introduced?
Fix issues in #2132 that also exposed some improvements to be made to the types in
useOptimisticCart()
.WHAT is this pull request doing?
HOW to test your changes?
Post-merge steps
Checklist