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

Incorrect inferred typing when using operation and endpoint #244

Open
jakeleventhal opened this issue Oct 2, 2023 · 6 comments
Open

Incorrect inferred typing when using operation and endpoint #244

jakeleventhal opened this issue Oct 2, 2023 · 6 comments

Comments

@jakeleventhal
Copy link
Contributor

jakeleventhal commented Oct 2, 2023

When making calls the API using inferred types (endpoint + operation), I am getting the wrong type for my payload variable.

const payload = await this.sellingPartner.callAPI({
  endpoint: 'finances',
  operation: 'listFinancialEventGroups',
  query: {
    FinancialEventGroupStartedAfter: startDate.toISOString()
  }
});
Screenshot 2023-10-02 at 4 53 03 PM

It seems to think that i should be destructuring payload when the value is already destructured. Below is what i see when i log payload

Screenshot 2023-10-02 at 4 53 51 PM
@jakeleventhal
Copy link
Contributor Author

@amz-tools

@jakeleventhal jakeleventhal changed the title Incorrect inferred typing when using operation and endpoint` Incorrect inferred typing when using operation and endpoint Oct 2, 2023
@jakeleventhal
Copy link
Contributor Author

jakeleventhal commented Nov 15, 2023

This is still an issue on 1.0.0 and is a blocker for wanting to have any sort of type inferencing

@jakeleventhal
Copy link
Contributor Author

I can fix this myself. Can @amz-tools please provide some guidance for how to fix this?

@curiousElf
Copy link

@jakeleventhal How did you go about fixing this? Do we need to rewrite all the nested types ourselves?

@jakeleventhal
Copy link
Contributor Author

@jakeleventhal How did you go about fixing this? Do we need to rewrite all the nested types ourselves?

import { GetOrderPath, GetOrderResponse } from 'amazon-sp-api/lib/typings/operations/orders';

  async getOrder(orderId: string): Promise<GetOrderResponse['payload']> {
    try {
      const order = await this.sellingPartner.callAPI({
        operation: 'orders.getOrder',
        path: { orderId } as GetOrderPath
      });

      return order;
    } catch (err) {
      const handledError = await this.handleAPIError(err);
      throw handledError;
    }
  }

annoying, but works

@jakeleventhal
Copy link
Contributor Author

@amz-tools any guidance here? Will gladly take this on.

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