Skip to content
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

product_data metadata typescript #342

Open
bfourgeaud opened this issue Jul 30, 2024 · 4 comments
Open

product_data metadata typescript #342

bfourgeaud opened this issue Jul 30, 2024 · 4 comments

Comments

@bfourgeaud
Copy link

Hello,

Does anyone have an idea how to augment the ProductAttributes.product_data interface in order to type the product metadata ?
I need this in order to handle my product variations, and handle subsequent api calls.

I tried creating a shoppingCart.d.ts file but it doesn not work. The interface seems not to be augmentable ...

import "use-shopping-cart"

declare module "use-shopping-cart" {
  interface ProductAttributes {
    product_data: {
      type: "MULTI" | "SINGLE"
      barcode?: string
      options?: string[]
      productId: string
      variantId?: string
    }
  }
}

This causes typescript to show errors when I try to access the item metadata
image

@dayhaysoos
Copy link
Owner

Hey @bfourgeaud, did you end up figuring this out? Sorry for the late response!

@bfourgeaud
Copy link
Author

@dayhaysoos still not found a way to type the metadata correctly.
I have, for now, created a custom type and casted the product_data as CustomType wherever I neded it ...

@dayhaysoos
Copy link
Owner

@bfourgeaud That's what I was going to suggest anyway, is there something you think I can do to the type so that you can get your desired results?

@bfourgeaud
Copy link
Author

I don't knwo why I can't extend this type.
Maybe because there is no declare module nor declare namespace inside the codebase ... So typescript can't augment these types ?

But for what is sure, is that declaring product_data?: object is quite bizzare in my opinion. At least product_data?: { [key: string]: any } to avoid errors.

But if someone arrives with better understanding of typescript modules, I would be glad. Because It would be the better way to be able to augment the metadata of the product in a d.ts file.

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

No branches or pull requests

2 participants