pino-http icon indicating copy to clipboard operation
pino-http copied to clipboard

Type incompatibility after upgrading pino to 8.6.0

Open ghost opened this issue 3 years ago • 5 comments
trafficstars

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.

ghost avatar Sep 20 '22 14:09 ghost

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

mcollina avatar Sep 24 '22 07:09 mcollina

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?

manvydasu avatar Oct 13 '22 06:10 manvydasu

@thomas-yaa The issue resolved for me after upgrading typescript to latest version (4.6 -> 4.8.4)

manvydasu avatar Oct 17 '22 13:10 manvydasu

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.

Nulifier avatar Nov 01 '22 17:11 Nulifier

cc @kibertoad

mcollina avatar Nov 01 '22 18:11 mcollina