-
Notifications
You must be signed in to change notification settings - Fork 686
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
[Typescript] Cannot call a namespace #62
Comments
Update: I've found a workaround, but it's not nice. import * as qrGenerator from 'qrcode-generator';
function myFunc() {
// @ts-ignore
const qr = qrGenerator.default(0, 'H');
qr.addData('Hello, world!');
qr.make();
} |
What about this? import qrcode from 'qrcode-generator';
componentDidLoad() {
const typeNumber = 4 as TypeNumber;
const errorCorrectionLevel = 'L' as ErrorCorrectionLevel;
const qr = qrcode(typeNumber, errorCorrectionLevel);
qr.addData('Hi!');
qr.make();
document.getElementById('placeHolder').innerHTML = qr.createImgTag();
} |
in the file "... node_modules/qrcode-generator/qrcode.d.ts" add
interface QRCodeFactory {
default (qrVersion: number, errorCorrectionLevel: string): QRCode;
stringToBytes(s: string) : number[];
stringToBytesFuncs : { [encoding : string] : (s: string) => number[] };
createStringToBytes(unicodeData: string, numChars: number) :
(s : string) => number[];
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
According to the typings from qrcode.d.ts, I should be able to do the following since the export is an instance of the
QRCodeFactory
interface which has the call signature(typeNumber: TypeNumber, errorCorrectionLevel: ErrorCorrectionLevel) : QRCode;
:However, the typescript compiler returns:
Alternatively, using
qrcode
like this compiles without a hitch:But it throws a runtime error:
The text was updated successfully, but these errors were encountered: