spree / spree-api-v2-js-sdk

Spree Storefront API JavaScript / TypeScript SDK
https://api.spreecommerce.org
MIT License
104 stars 41 forks source link

SDK types found but empty, and autocompletion not working #366

Closed babgyy closed 1 year ago

babgyy commented 1 year ago

Context

I am using v6.0.3 of the SDK, and am trying to use the storefront checkout methods. The code works, but type definitions are listed as any, and autocompletion does not work.

This sample for instance won't find type informations for checkout and orderUpdate

import createFetchFetcher from '@spree/node-fetcher';
import { makeClient } from '@spree/storefront-api-v2-sdk';

const client = makeClient({
  host: `https://example.com/spree/`,
  createFetcher: createFetchFetcher,
});

const response = await client.checkout.orderUpdate({});

image image

Expected Behavior

I am no typescript expert, but I think types should be inferred. Typing

client. 

should/could suggest autocompletions for method of the interface Client such as Checkout and so on ?

This was working in a previous project using v4 of this SDK

Possible Fix

No idea

Your Environment

I am using VSCode

"dependencies": {
    "@apollo/client": "^3.7.6",
    "@hookform/resolvers": "^2.9.11",
    "@lingui/react": "^3.17.0",
    "@segment/analytics-next": "^1.51.1",
    "@spree/node-fetcher": "^1.0.0",
    "@spree/storefront-api-v2-sdk": "^6.0.3",
    "@types/humps": "^2.0.2",
    "date-fns": "^2.29.3",
    "graphql": "^16.6.0",
    "humps": "^2.0.1",
    "lodash": "^4.17.21",
    "lottie-react": "^2.4.0",
    "marked": "^4.2.12",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-hook-form": "^7.43.1",
    "react-router-dom": "^6.8.0",
    "react-scripts": "5.0.1",
    "survey-core": "^1.9.74",
    "survey-react-ui": "^1.9.71",
    "tailwindcss": "^3.2.4",
    "typescript": "^4.9.4",
    "web-vitals": "^2.1.4",
    "wretch": "^2.4.1",
    "zod": "^3.20.6",
    "zustand": "^4.3.2"
  },
babgyy commented 1 year ago

If it can help, I have reproduced the issue with a minimal setup on stackblitz here : https://stackblitz.com/edit/typescript-whunwk?file=index.ts

fpdrozd commented 1 year ago

@babgyy Thank you for your help! We have identified the issue and I'm working on it.

fpdrozd commented 1 year ago

@babgyy Hi! You can now bump the SDK's version to v6.0.4 and autocompletion should work. In VS Code you might also need to restart the Typescript server.

babgyy commented 1 year ago

Hey @fpdrozd Thanks for working on it. I have tried v6.0.4, it's better : I have now autocompletion on IClientConfig

However IOrderResult does not seem to be exported, so I can't carry this type around in my code. Is it desired behavior ?

fpdrozd commented 1 year ago

@babgyy The way we bundle type definitions now caused the issue with IOrderResult not being exported. I've added two more fixes for it that are now available in v6.0.5. Let me know if that works :)