ค้นหาเว็บไซต์

node.js - แปลง express Response เป็น http ServerResponse


ฉันกำลังใช้ทั้ง express และ http-proxy หลังจากอัปเดตประเภทของ NodeJs ฉันได้รับข้อผิดพลาดเกี่ยวกับชนิด:

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'.

ในบล็อกโค้ดต่อไปนี้:

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

ดังนั้นตอนนี้ฉันไม่แน่ใจว่าจะเปลี่ยนข้อมูล Response นั้น (มาจาก express) ให้เป็นชนิด ServerResponse ที่ http-proxy ดูเหมือนว่าจะคาดหวังไว้อย่างไร

มีข้อเสนอแนะอะไรไหม?