dts2hx
dts2hx copied to clipboard
Should extend by using a class error in Got library
I'm using Got for http requests and received the following error after using dts2hx to generate externs:
/11,8,0/got/RequestError.hx:7 : Should extend by using a class
referring to this line in /got/RequestError.hx:
@:jsRequire("got", "RequestError") extern class RequestError extends global.nodejs.ErrnoException
Taking a look at ErrnoException.hx we see it's generated as a typedef:
package global.nodejs;
typedef ErrnoException = {
@:optional
var errno : Float;
@:optional
var code : String;
@:optional
var path : String;
@:optional
var syscall : String;
@:optional
var stack : String;
var name : String;
var message : String;
};
As a quick fix I just turned this into a class to get it working.
#15 looks similar and so maybe this isn't a dts2hx issue, but a ts definition problem?
Or should ErrnoException be generated as a class since it extends Error (I'm not familiar with TypeScript)?
I also noticed the "Interface extends" line item under your roadmap, so maybe you're already aware of this!
Thanks.
Hey, thanks for the report :), not sure what's going wrong here! Definitely a bug my end, I'll investigate
Edit: turns out in typescript a class can extend an interface – this doesn't work in haxe so to translate to haxe we can merge the interface into the class
FYI, if you try to run dts2hx on Got, there are a few libs that don't automatically have externs created by dts2hx when running npx dts2hx got and so I had to manually invoke dts2hx for them:
- @szmarczak/http-timer
- cacheable-lookup
- cacheable-request
- responselike
Is this behavior intended? I know it auto generates on other dependencies, so I'm unsure as to why it doesn't for these four.
Yeah it should be generating externs automatically if they're used by Got, do you get errors about missing types then?
Hmm, my typescript is producing errors if I try to extend a class with an interface ¯\_(ツ)_/¯, maybe it's a recent addition. I'll get to the bottom of it
Oops, I forgot to include the errors that appear when I run dts2hx on cacheable-lookup:
> Converting module cacheable-lookup
> Error: [TypeScript 3.7] Cannot find module 'dns'. (C:/test/node_modules/cacheable-lookup/index.d.ts:1:57)
> Error: [TypeScript 3.7] Cannot find module 'http'. (C:/test/node_modules/cacheable-lookup/index.d.ts:2:21)
> Error: [TypeScript 3.7] Cannot find namespace 'NodeJS'. (C:/test/node_modules/cacheable-lookup/index.d.ts:102:63)
> Error: [TypeScript 3.7] Cannot find namespace 'NodeJS'. (C:/test/node_modules/cacheable-lookup/index.d.ts:103:45)
> Error: [TypeScript 3.7] Cannot find namespace 'NodeJS'. (C:/test/node_modules/cacheable-lookup/index.d.ts:104:83)
> Error: [TypeScript 3.7] Cannot find namespace 'NodeJS'. (C:/test/node_modules/cacheable-lookup/index.d.ts:105:69)
> Saved externs for cacheable-lookup into .haxelib/cacheable-lookup/5,0,3/
Everything else runs without errors and just for reference Got shows this output when generating externs, so it's missing the other four:
> Converting module got
> Saved externs for got into .haxelib/got/11,8,0/
> Converting module node
> Saved externs for node into .haxelib/node/14,14,2/
> Converting module p-cancelable
> Saved externs for p-cancelable into .haxelib/p-cancelable/2,0,0/
Ahh, I understand whats going on with the interface business: Error has a special 'ConstructorType' variable declaration in addition to an interface
declare var Error: ErrorConstructor
And apparently that can be extended as if it was a class. This is on the roadmap as "Exported variables to class promotion", so when that's in, a separate Error class will be generated and this issue will be resolved. Might take a while however as I'm currently not dedicating a lot of time to dts2hx because of other work constraints
I'll open a separate issue for the dependency issue, thanks for reporting that too
Sounds, good. Thanks!