Deishelon / google-play-billing-validator

Npm module for Node.js to validate In-app purchases and Subscriptions on your backend
https://medium.com/androidhub/how-to-validate-in-app-purchase-subscription-on-your-node-js-backend-a2b823470034
90 stars 32 forks source link

Allow default import syntax from TypeScript #19

Closed unpollito closed 3 years ago

unpollito commented 3 years ago

Description

Currently, importing the library from TypeScript doesn't work as advertised. According to the types file, it should be imported like this:

import googleVerify from "google-play-billing-validator";
new googleVerify({ email: "foo", key: "bar" });

However, while this compiles, it causes a runtime error: TypeError: google_play_billing_validator_1.default is not a constructor

It's currently possible to make this work with TypeScript, but it forces the user to force a cast, which defeats the purpose of using types:

import * as googleVerify from "google-play-billing-validator";
// needs "as any", or it won't compile
new (googleVerify as any)({ email: "foo", key: "bar" });

Adding the default import syntax would allow the code from the first example to work as advertised, and is also a typical solution (e.g., off the top of my mind, Axios does this).

Types of changes

Documentation:

vintage commented 3 years ago

Just been integrating the lib today and hit the TypeError: google_play_billing_validator_1.default is not a constructor. Default import syntax should be definitely supported out of the box. @Deishelon got chance to take a look at it?

Deishelon commented 3 years ago

LGTM! Thanks 💕