pino-http
pino-http copied to clipboard
Type incompatibility after upgrading pino to 8.6.0
Upgraded pino to latest release, 8.6.0 in a project using Next.js, pino, and pino-http.
A test that assigns the log field on a NextApiRequest as part of its setup now fails with the following error:
Type 'Logger<LoggerOptions | DestinationStream>' is not assignable to type 'LoggerExtras<LoggerOptions>'
I tried to use a mock instead and still encountered the error.
Thanks for reporting!
Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.
cc @kibertoad for his TS experience
Hey @mcollina
I've noticed the similar behavior after upgrading to latest pino and pino-http, not sure if the usage is incorrect, but after upgrading such code no longer works. (pino.Logger and resulting type from req.log.child can not casted to same type)
let childLogger: pino.Logger | null = null;
childLogger = req.log.child({ test: 'test' });
And then the error looks like this:
TS2322: Type 'Logger<LoggerOptions & ChildLoggerOptions>' is not assignable to type 'Logger<LoggerOptions> | null'. Â Â Type 'Logger<LoggerOptions & ChildLoggerOptions>' is not assignable to type 'Logger<LoggerOptions>'. Â Â Â Â Property 'onChild' is missing in type 'BaseLogger & LoggerExtras<LoggerOptions & ChildLoggerOptions> & Record<never, LogFn>' but required in type 'LoggerExtras<LoggerOptions>'.
Previously it was possible to use pino.Logger and child logger from req.log.child as a same type. Maybe it's an issue of pino though.
Is this example enough?
@thomas-yaa The issue resolved for me after upgrading typescript to latest version (4.6 -> 4.8.4)
I'm on the latest version of typescript (4.8.4) and I'm still experiencing the same issue. I'm trying to pass an existing pino logger instance to pino-http and I get the same error. Here is a simple example:
import pino from "pino";
import pinoHttp from "pino-http";
const log = pino();
const httpLogger = pinoHttp({ logger: log });
const httpLogger2 = pinoHttp({ logger: log.child({ m: "test" }) });
Casting the logger to any and then passing it to the logger option works as a temporary workaround.
cc @kibertoad