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

[BUG] ICheckout types are not exported #450

Closed
splacentino opened this issue May 15, 2020 · 6 comments
Closed

[BUG] ICheckout types are not exported #450

splacentino opened this issue May 15, 2020 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@splacentino
Copy link

When working with Typescript, I'd like to use pre-built types from ICheckout (and other) namespace (AccountInfo, ...).
Because they have no export prefix, tsc compiler does not recognize and process them.

To Reproduce

  1. Declare a function as this:
export function getPaymentMethods(): Promise<ICheckout.PaymentResponse> {
  return return checkout.paymentMethods({...})
}

Where you CANNOT import the specific interface as

import { PaymentResponse /*, ICheckout */ } from "@adyen/api-library"

nor

import { PaymentResponse /*, ICheckout */ } from "@adyen/api-library/dist/lib/src/typings/checkout";
  1. Build your code using tsc --build (this code is part of a composite project).

Expected behavior
Successful build.

Actual behaviour

$ tsc --build
../composite-project/dist/src/adyen.d.ts:73:13 - error TS2503: Cannot find namespace 'ICheckout'.

73 }): Promise<ICheckout.PaymentMethodsResponse>;

Desktop (please complete the following information):

  • OS: Mac | Linux
  • Node Version: 12.14
  • NPM Version: 6.13
  • Adyen version: 3.1.3
@splacentino splacentino added the bug Something isn't working label May 15, 2020
@KadoBOT
Copy link
Contributor

KadoBOT commented May 15, 2020

Hi @splacentino

You don't import type definition files. All types are already compiled and available within the library (see here), which means you don't need to import the types to use them if you are using the library.

I just tested your code, and this works:

import { Client, CheckoutAPI } from '@adyen/api-library'

const client = new Client({ apiKey: '1234', environment: 'TEST' })
const checkout = new CheckoutAPI(client)

function getPaymentMethods(): Promise<ICheckout.PaymentMethodsResponse> {
    return checkout.paymentMethods({ merchantAccount: 'testMerchantAccount' })
}

Also, in your case, the return type is inherited, based on the type definitions of the checkout.paymentMethods. Since you manually specified the return type, you are telling the compiler that the expected return type is PaymentResponse, when the correct one is PaymentMethodsResponse, which is wrong. So in this case, you don't need to specify the return type:
image

@KadoBOT
Copy link
Contributor

KadoBOT commented May 15, 2020

Since this is not a bug, I'll close the issue. But feel free to leave any comments.

@KadoBOT KadoBOT closed this as completed May 15, 2020
@splacentino
Copy link
Author

splacentino commented May 15, 2020

Hi @KadoBOT

I made a typo in the example, indeed.

Self types import does not look good enough. Could you try with two separate projects a and b where b is composite ts project imported in project a.

Transpilation of project b when building project a (tsc --build) will throw an error regarding types.

@KadoBOT
Copy link
Contributor

KadoBOT commented May 15, 2020

How the project is currently set up, it expects you to have the library installed. So it indeed it might fail for cases like yours. If you need to use the types on a different project, you would need the types to be independent, in other words, to be a package (i.e @types/@adyen/api-library).

If you feel like, you can open a feature request for that, but that would depend on more requests as is not a priority for us right now. Or, you can add the types to the @types repo yourself.

Lemme know if that helps.

@splacentino
Copy link
Author

@KadoBOT Thank you for your advices.

Regarding your previous message I was able to apply workaround:

  1. import "@adyen/api-library/dist/lib/src/typings"; in specific file
  2. "declaration": true in composite tsconfig.json project

@KadoBOT
Copy link
Contributor

KadoBOT commented May 15, 2020

@splacentino that's great! Thanks for the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants