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

Update Type Decleartions(?) #883

Open
MurmeltierS opened this issue Mar 8, 2022 · 16 comments
Open

Update Type Decleartions(?) #883

MurmeltierS opened this issue Mar 8, 2022 · 16 comments

Comments

@MurmeltierS
Copy link

The TypeScript Type Declarations are a far shot from whats actually delivered by the API.
How is this even possible?

@fmoessle
Copy link

fmoessle commented Mar 9, 2022

I think this happens easily because the types are shipped via @types/shopify-buy and are not included in the shopify-buy package itself. Would love to see them updated though :)

@MurmeltierS
Copy link
Author

@fmoessle Our intern is now tasked with writing accurate definition.

@janbaykara
Copy link

big if true

@MurmeltierS
Copy link
Author

MurmeltierS commented Apr 14, 2022

@janbaykara

We are currently in preperation of a PR for DefinitelyTyped.
Until then, our typings are available via https://www.npmjs.com/package/@brandboostinggmbh/shopify-buy-types

Simplest way to use them is via npm i @types/shopify-buy@npm:@brandboostinggmbh/shopify-buy-types

@janbaykara
Copy link

Thanks very much @MurmeltierS!

@MurmeltierS
Copy link
Author

MurmeltierS commented Apr 17, 2022

Thanks very much @MurmeltierS!

Thanks are due to our intern @einzN, who wrote most of the delcarations.

@sharathnraj
Copy link

Can I please request that you add presentmentCurrencyCode as one of the props accepted in CheckoutResource for creating a checkout ??
Thanks in advance @einzN and @MurmeltierS.

@MurmeltierS
Copy link
Author

Can I please request that you add presentmentCurrencyCode as one of the props accepted in CheckoutResource for creating a checkout ?? Thanks in advance @einzN and @MurmeltierS.

@einzN can you take a look at this

@fmoessle
Copy link

fmoessle commented May 4, 2022

Dear Shopify developers,

please consider updating the type definitions for this project. Working with it in TypeScript is an absolute nightmare.

@pfych
Copy link

pfych commented May 25, 2022

The type declarations in @types/shopify-buy are now out of date.

Line item type declarations caught me off guard since the type declaration says price is accessible at lineItem.price, However they are now accessed at lineItem.variant.price.

A types.d.ts file in this project would be insanely appreciated!

Edit:
I was able to run graphql-codegen with the following config added to this projects root:

# codegen.yml
schema: ./schema.json
generates:
  ./src/types.ts:
    plugins:
      - typescript

I then added the following packages to this projects dependencies:

{
  "dependencies": {
    "@graphql-codegen/cli": "^2.6.2",
    "@graphql-codegen/typescript": "^2.4.11",
    "graphql": "^16.5.0"
  }
}

and ran this command from this projects root:

./node_modules/@graphql-codegen/cli/bin.js --config codegen.yml

This generates a typescript file with types that can be used with a bit of effort however it solved my issue. I continue to use @types/shopify-buy but if a type is wrong I can use the types from this gql hack.

Example:

// Before
TS2551: Property 'variant' does not exist on type 'LineItem'. Did you mean 'variantId'?
     99 |               userCart.lineItems.map((item) => (
    100 |                 <li key={item.id}>
  > 101 |                   {item.title} @ ${item.variant.price || '0'}
        |                                         ^^^^^^^
    102 |                 </li>
    103 |               ))
    104 |             )}
// After
// I have to cast to unknown first since old types has id as number or string whereas gql has id as string
(userCart.lineItems as unknown as CheckoutLineItem[]).map(
  (item) => (
    <li key={item.id}>
      {item.title} @ ${item.variant.price || '0'}
    </li>
  ),
)

This solution is not perfect but it provides interfaces for most objects, a good hack for now until there are official types.

@dilloncoffman
Copy link

Thank you @einzN!

Thanks very much @MurmeltierS!

Thanks are due to our intern @einzN, who wrote most of the delcarations.

@magoz
Copy link

magoz commented Jun 14, 2022

We are currently in preperation of a PR for DefinitelyTyped. Until then, our typings are available via https://www.npmjs.com/package/@brandboostinggmbh/shopify-buy-types

Simplest way to use them is via npm i @types/shopify-buy@npm:@brandboostinggmbh/shopify-buy-types

@MurmeltierS I'm using them but I encountered several types that are incorrect.

For instance ShopifyBuy.Cart.discountApplications is typed as string[] but it's actually an object with multiple properties:

Screen Shot 2022-06-14 at 21 21 14

How is the PR for DefinitelyTyped going? Any updates?

I'm happy to contribute if you need help.

@MurmeltierS
Copy link
Author

@magoz sry, we were a little busy with other things at the moment.
if you encounter any errors feel free to open a pr at https://github.com/Brand-Boosting-GmbH/shopify-buy-types

@JWizerd
Copy link

JWizerd commented Nov 22, 2022

Hello, just adding to the thread of repeat complaints that the typings are out of date... again.

The latest typings are outdated with the current latest release (2.17.1). The variant interface is my primary pain point as it's no longer using "string" as it's type for price, but using the PriceV2 interface. However, as you can imagine since the ProductVariant interface is being used by other interfaces such as Product and LineItem this kinda a pain in the ass and has lead me to have to extend the ShopifyBuy namespace and start extending interfaces and omitting properties to accommodate for this.

Any ETA on when you'll be releasing an updated version?

@MurmeltierS
Copy link
Author

@JWizerd Since we moved away from using the "js-buy-sdk" we aren't actively working on our type declerations anymore.
Shopify also seems to have no interest in providing TypeScript Support.

My only suggestion for you would be to use the GraphQL Storefront API directly in combination with graphql-codegen to generate types on the fly.
If you've never used GraphQL before, this might sound a little overwhelming, but I can pretty much guarantee you that that will be a lot more future-proof than this (unloved) package here.

@Nikola-Milovic
Copy link

Brand boostings types are outdated, and the definitely typed seems to be outdated as well now. What are you guys using if anything for the types? Seems absurd that this is still an issue

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

9 participants