Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript typing error, HttpRequest do not match with http.IncomingMessage on`http.createServer()` #43

Closed
nolanrigo opened this issue Jun 2, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@nolanrigo
Copy link

commented Jun 2, 2018

Hello 馃憢 a big thanks for this library, RxJS as http server is really awesome 馃槏

Describe the bug

I got a typing issue with @marblejs/core on my typescript project,
I created a listener (httpListener()) and created a http server (http.createServer(app)) but got a typing error :

Argument of type '(req: HttpRequest, res: HttpResponse) => void' is not assignable to parameter of type '((request: IncomingMessage, response: ServerResponse) => void) | undefined'.
  Type '(req: HttpRequest, res: HttpResponse) => void' is not assignable to type '(request: IncomingMessage, response: ServerResponse) => void'.
    Types of parameters 'req' and 'request' are incompatible.
      Type 'IncomingMessage' is not assignable to type 'HttpRequest'.
        Property 'matchPath' is missing in type 'IncomingMessage'.

createServer(app).listen(

This error is thrown only when strictFunctionTypes is activated on my compiler config

{
  "compilerOptions": {
    "strictFunctionTypes": true
  }
}

To Reproduce

I create a branch on my project to reproduce the issue (https://github.com/zap4you/server/tree/marblejs-issue)

$ git clone git@github.com:zap4you/server.git marblejs-issue
$ cd marblejs-issue
$ git checkout marbejs-issue
$ npm i
$ npm run build

Expected behavior
I'm not sure but the function that httpListener returns should be more strictly typed to match with http.createServer expectation ?!.

Desktop (please complete the following information):

 - macOs 10.13.4
 - node@9.11.1 / npm@6.1.0
 - typescript@2.9.11
 - @marblejs/core@0.4.0
 - @types/node@10.1.2

@nolanrigo nolanrigo changed the title Typescript typing error by `httpListener()` on `http.createServer()` Typescript typing error, HttpRequest do not match with http.IncomingMessage on`http.createServer()` Jun 2, 2018

@JozefFlakus

This comment has been minimized.

Copy link
Member

commented Jun 2, 2018

Hi, thanks for kind words!

It turned out that our example project hid this error thanks to missing type definition for app parameter. 馃檲

const createServer = app => {
  ...
};

I've created a PR #44 with solution to this problem. The fix will be available in version 0.4.1. I'll let you know when it will be ready.

Cheers!

@JozefFlakus JozefFlakus added this to the v0.4.1 milestone Jun 2, 2018

@JozefFlakus JozefFlakus added the bug label Jun 2, 2018

@nolanrigo

This comment has been minimized.

Copy link
Author

commented Jun 2, 2018

Thanks for the fast fix 馃挭. I let you close this issue when is needed.

@JozefFlakus

This comment has been minimized.

Copy link
Member

commented Jun 3, 2018

@nolanrigo version 0.4.1 is released. You can check a changelog here 馃挭

@JozefFlakus JozefFlakus closed this Jun 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.