Search code examples
node.jstypescriptwinston

Typescript: Method to implement an interface with 3 different signatures?


I am trying to wrap a function/method available in winston (node loggin framework), I have found its interface

interface LeveledLogMethod {
    (msg: string, callback: LogCallback): LoggerInstance;
    (msg: string, meta: any, callback: LogCallback): LoggerInstance;
    (msg: string, ...meta: any[]): LoggerInstance;
}

I would like to implement a method called "error" that would take the above signatures.

I am only wrapping it, so I will be calling the winston function directly.

If anybody is familiar with winston, I basically have 2 loggers setup and all consumers go through my main loggging class and I use either the 1st logger or second logger depending on the loglevel so I need to wrap it.


Solution

  • Use 3 interfaces this way:

    interface A {}
    interface B {}
    interface C {}
    
    const variable: A|B|C = {};