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

TypeError every time use enum #162

Open
djmanaluu opened this issue Jun 22, 2022 · 1 comment
Open

TypeError every time use enum #162

djmanaluu opened this issue Jun 22, 2022 · 1 comment

Comments

@djmanaluu
Copy link

djmanaluu commented Jun 22, 2022

I use Xendit in my NodeJS and using TypeScript.
I tried to call EWallet.createEWalletCharge(args: {}) and QrCode.createCode(args: {}) and get TypeError: Cannot read properties of undefined to all parameters that use your enum. (in my case Currency, ChannelCode, QrCodeTypes)

I think because the enum is not convert properly to be string in the javascript code (🤔 just my opinion, still not sure because haven't check it deeper).

I think despite of using enum, better for you to use Union Type and the we still can get the value suggestion too like the image I put below.

So here's the example:

// BEFORE:
enum Currency {
  IDR = 'IDR',
  PHP = 'PHP',
}

// AFTER:
type Currency = 'IDR' | 'PHP';

Maybe you can change all enum into union type like that.

And I found 1 more problem, ChannelCode in ewallet_charge.d.ts not cover all of the ewallet method.

Thank you.

NOTE:

  1. Image for the value suggestion if using union type

Screen Shot 2022-06-22 at 10 34 23

  1. How to repo the error:
    Just run this code
try {
    const xendit = new Xendit({
        secretKey: "xnd_development_xxxxxxxxxxxxxxxxxx"
    });

    const result = await new PaymentGateway.EWallet({}).createEWalletCharge({
        referenceID: "ID",
        currency: Currency.IDR,
        amount: 9999,
        checkoutMethod: "ONE_TIME_PAYMENT",
        channelCode: ChannelCode.ID_OVO,
        channelProperties: {
            mobileNumber: "+628123423423"
        }
    });
} catch (error) {
    console.log(error);
}
@adityarx
Copy link

adityarx commented Jun 8, 2023

Hi @djmanaluu a little bit of a late response but we are trying to figure out the best way to fix this at the moment. In the meantime, please use the unideal way of casting strings as any fit into the type temporarily 🙏

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