0

I'm trying to overwrite the node express send method of the Response type. The method is of type Send that is defined as such:

interface Send {
    (status: number, body?: any): Response;
    (body?: any): Response;
}

My objective is to add local logging of the response send with express, but I can't make an implementation of this type, even as a function like explained in other questions like this.

Community
  • 1
  • 1
nonelse
  • 23
  • 5

1 Answers1

0

That interface describes a function with two signatures, you can implement it like so:

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();
}
Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
  • Although technically correct, the `= (...) =>` format binds `this` to the current class in my setup, making it not work with express send function. Instead, I found and used [express-mung](https://www.npmjs.com/package/express-mung), that achieves what I initially wanted to do. – nonelse May 19 '17 at 13:09