pinojs/pino

TypeScript interface LogFn bugged (e.g. logger.info, logger.debug, etc.)

Zamiell opened this issue · 5 comments

The normal usage for Pino is to use one argument, like this:

logger.info("foo"); // "foo" is logged.

If you try to use 2 arguments, Pino will use the second argument as a string interpolation argument. However, Pino will silently drop the second argument it if you don't have any % signs in your first argument:

logger.info("foo", "bar"); // "foo" is logged, but "bar" is dropped.

The TypeScript definitions for Pino are therefore bugged, as the TypeScript compiler does not throw an error when you supply a second argument.

In order to fix this problem, I believe that the type definitions for the function need to be more specific.

Ok, I spent a few hours on this and I think I have a pretty good fix for the bug.

I covered every test case that I could think of.
Thanks to -n- and Burrito in the TypeScript Discord for helping me create this.

I just updated the playground to account for functions being passed, which should be disallowed now.

I can submit a PR if needed.

Send it over, thanks!