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

Wrong type for options in productService.listProductVariants #9418

Open
Alexnortung opened this issue Oct 1, 2024 · 1 comment
Open

Wrong type for options in productService.listProductVariants #9418

Alexnortung opened this issue Oct 1, 2024 · 1 comment

Comments

@Alexnortung
Copy link
Contributor

Bug report

Describe the bug

When trying to find product variants, the options filter seems to be wrong, the current type is Record<string, string>. But this is not actually correct.

const existingProductVariants = await productService.listProductVariants({
    product_id: product.id,
    options: { color, size },
});

The following seems to work as expected, however it does give me a type error, so for now I will use @ts-expect-error.

const existingProductVariants = await productService.listProductVariants({
    product_id: product.id,
    options: [
        {
            value: color,
        }, {
            value: size,
        }
    ],
});

Expected behavior

I expected the query to work when providing the required typescript types.

Screenshots

billede

@naaa760
Copy link

naaa760 commented Oct 2, 2024

Hello @Alexnortung :)

fix: #9418

The type definition of the options argument, which is presently set to Record<string, string>, needs to be updated in order to fix the type error in the **productService.listProductVariants** function. The expected structure for product variants is not followed by this definition. To accept an array of objects, each with a value property, we should alter the type instead. The following should be the amended type definition: **type Option = { value: string }; **listProductVariants(params:** { product_id: string; options: Option[] }): Promise<ProductVariant[]>;.** This modification will enable the function to be implemented and used properly by calling it with an array of option objects, such as [{ value: color }, { value: size }], without encountering type errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants