haxiomic / dts2hx

Converts TypeScript definition files (d.ts) to haxe externs (.hx) via the TypeScript compiler API
MIT License
134 stars 9 forks source link

jsPDF --global does not produce externs #120

Closed rb1147x closed 2 years ago

rb1147x commented 2 years ago

Hi,

I'm trying to use the jsPDF library - https://github.com/parallax/jsPDF and they include TS definitions. However, when I run dts2hx with --global against this lib it does not appear to produce externs (except several TS type helper files, e.g. AnyOf2.hx).

When I run the command without --global or with --modular it generates the haxe externs. Since this is a library to be used client-side in the browser, am I doing something wrong with attempting to generate externs for this lib?

Thanks.

haxiomic commented 2 years ago

It looks like jsPDF doesn't define global types, everything is wrapped in the module "jsPDF" which must be imported because quotes are used

You can verify this by creating a .ts file and trying to access jsPDF through autocomplete (it'll add the import line for you)

So right now this seems to be working as expected given the type definitions

If jsPDF does define a global scope variable, then the ts definitions could be modified upstream to correct

rb1147x commented 2 years ago

Ahh, I think I understand. Thanks for the explanation.

haxiomic commented 2 years ago

You could use something like esbuild on the haxe output, so the require() calls get inlined, checkout the three.js example in this repo for how to do that

rb1147x commented 2 years ago

Right, I saw that and will check it out. Thanks!