Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type incompatibility after upgrading pino to 8.6.0 #247

Open
ghost opened this issue Sep 20, 2022 · 5 comments
Open

Type incompatibility after upgrading pino to 8.6.0 #247

ghost opened this issue Sep 20, 2022 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 20, 2022

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.

@mcollina
Copy link
Member

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

@manvydasu
Copy link

manvydasu commented Oct 13, 2022

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
Copy link

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

@Nulifier
Copy link

Nulifier commented Nov 1, 2022

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.

@mcollina
Copy link
Member

mcollina commented Nov 1, 2022

cc @kibertoad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants