clemos / haxe-js-kit

Haxe tools and externs for Javascript and Node.js
MIT License
128 stars 42 forks source link

Request object not unifying with IncomingMessage #177

Open fullofcaffeine opened 5 years ago

fullofcaffeine commented 5 years ago

Why doesn't js.npm.express.Request from haxe-js-kit unify with js.node.http.IncomingMessage? If you check the definition for the Express Request object, here: https://github.com/expressjs/express/blob/master/lib/request.js, you'll see that it extends http.IncomingMessage. The express TS type definitions seem to be ok, the req object passed by the use method callback correctly unifies with IncomingMessage, i.e:

Typescript code:

function bar(foo: http.IncomingMessage) {}
app.use('/tink_api', (req: express.Request, res: express.Response, next) => {
  bar(req); // works fine, no TS errors
});

But that doesn't work with Haxe when using js-kit:

Haxe code:

function bar(foo: js.node.http.IncomingMessage) {}
app.use('/tink_api', (req: js.npm.express.Request, res: js.npm.express.Response) -> {
      bar(req);  // errors with js.npm.express.Request should be js.node.http.IncomingMessage For function argument 'foo'
    });

Maybe the extern defs for express.Request in js-kit are wrong? I find it hard to believe that a project in the making for so many years missed something like that. Or maybe I'm missing something?

clemos commented 5 years ago

Hi, Unfortunately the project has not been very active for the last few years. Also, historically, haxe-js-kit had its own nodejs externs, which may explain lack of unification here and there. Anyway, feel free to submit a pull request :)

fullofcaffeine commented 5 years ago

Thanks @clemos, I hope life is treating you well, man! I'll have a peek at fixing it.

It's sad to see this project dying, hopefully someone will take it over. I think in fact the @HaxeFoundation should perhaps consider maintaining this (pour some money maybe) as I think these externs are critical for the success of Haxe-as-a-better-js/ts.

clemos commented 5 years ago

Life's great, I hope it's the same for you ;) I think what's leaking here is a maintainer, at least; I'm not sure money would help.

fullofcaffeine commented 5 years ago

I managed to fix this, although I'm not sure how good the solution is and if it'll work in all cases. I'll push a PR in the next few days.