3

I am using both express and http-proxy. After updating NodeJs types I am getting a type error:

TS2345: Argument of type 'Response<any, Record<string, any>>' is not assignable to parameter of type 'ServerResponse'.   Types of property 'req' are incompatible.     Type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>> | undefined' is not assignable to type 'IncomingMessage'.       Type 'undefined' is not assignable to type 'IncomingMessage'.

in the following code block:

async proxyCall(req: Request, res: Response): Promise<ProxyCallResponse> {
  return new Promise((resolve, reject) => {
    this.pendingPromises.set(req, {resolve, reject});
    this.proxy.web(req, res);
  });
}

so now I am not sure how to convert that Response input (coming from express) to the ServerResponse type that http-proxy seems to be expecting.

Any suggestion?

Apoorva Chikara
  • 8,277
  • 3
  • 20
  • 35
fusio
  • 3,595
  • 6
  • 33
  • 47
  • Can you show what imports you have, especially for the types? I'm wondering if you need to import `Request` and `Response` from `express`, as it would probably use the ones from `lib.dom.d.ts` otherwise. Also, it might be helpful to add some more context to what you mean by "After updating NodeJs types". Presumably you have recently updated something. Was it `@types/node`? If so, from what version and to what version? – jrasm91 Sep 12 '21 at 03:15
  • I am importing `Request` and `Response` from `express`. It is `@types/node`: from `15.x` to `16.x` so I imagine there is some breaking change in the typings causing the error.. – fusio Sep 13 '21 at 07:07
  • `function test(req: Request, res: Response, proxy: Server) {proxy.web(req, res);}` works for me with `@types/node: 16.x`. Which version of `@types/express` are you using? – Heiko Theißen Sep 13 '21 at 14:34
  • `"@types/express": ^4.17.13` and `express: ^4.17.1` – fusio Sep 15 '21 at 08:15
  • ooof. the only version of `@types/node` that does not give me issues is 15.6.1 - higher than that (e.g. 15.9.0) I get the error mentioned in the description above. – fusio Sep 16 '21 at 12:54

0 Answers0