yWorks / jsPDF

JavaScript PDF generation to work with SVG
MIT License
56 stars 23 forks source link

Typescript Types missing in the npm package #27

Open bpasham opened 5 years ago

bpasham commented 5 years ago

Seems like types are well created but doesn't seem to be included in the npm package. Including them will help a lot of folks who are struggling to use this package in Typescript projects.

Also Thank you for all the hard work you put into this project.

HackbrettXXX commented 5 years ago

You are right. We also should update the types first, since they were merged/copied from upstream and are missing some methods from this fork.

Danebrouwer97 commented 4 years ago

How do I get and use the typings file? I see they exist, but if I try copy+paste the code over into an index.d.ts file, TS just complains that it is not a module.

File '.../jspdf-yworks/index.d.ts' is not a module.

Edit: Found the solution. Change:

declare module 'jspdf' {
    // ... Interfaces ...
    class jsPDF { ... }
    namespace jsPDF { }

    export = jsPDF;
}

To:

declare namespace jsPDF {
    // ... Interfaces ...
    class jsPDF { ... }
}
export = jsPDF;

Update: This solves any issues thrown by typescript, but fails in actual use. Likely because it's no longer a module that exports an actual class. I know nothing of creating Typings files, and only have a basic knowledge of producing typesafed code, so this is honestly all trial and error.

TypeError: jspdf_yworks__WEBPACK_IMPORTED_MODULE_5__.jsPDF is not a constructor
HackbrettXXX commented 4 years ago

Great you found the solution. A release where the types are included in the npm package is already in the pipeline.