Express 带有混合接口的Typescript覆盖快速发送功能
我正在尝试覆盖Express 带有混合接口的Typescript覆盖快速发送功能,express,typescript,hybrid,Express,Typescript,Hybrid,我正在尝试覆盖Response类型的node expresssend方法。 该方法的类型为Send,定义如下: interface Send { (status: number, body?: any): Response; (body?: any): Response; } 我的目标是为使用express发送的响应添加本地日志记录,但我无法实现这种类型,即使是像其他问题中解释的函数。该接口描述了一个具有两个签名的函数,您可以这样实现它: const fn: Send = (f
Response
类型的node expresssend
方法。
该方法的类型为Send
,定义如下:
interface Send {
(status: number, body?: any): Response;
(body?: any): Response;
}
我的目标是为使用express发送的响应添加本地日志记录,但我无法实现这种类型,即使是像其他问题中解释的函数。该接口描述了一个具有两个签名的函数,您可以这样实现它:
const fn: Send = (first?: any, second?: any) => {
if (first && second) {
// deal with (status: number, body: any)
} else if (first) {
// deal with (status: number) or (body: any)
} else {
// deal with ()
}
return new Response();
}
虽然技术上正确,但是
=(…)=>
格式将此
绑定到我的设置中的当前类,使其无法与express send函数一起使用。相反,我发现并使用了它,它实现了我最初想要做的事情。