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

CustomLevels typing not being repassed to child #1703

Closed
matheusvellone opened this issue May 3, 2023 · 2 comments · Fixed by #1704
Closed

CustomLevels typing not being repassed to child #1703

matheusvellone opened this issue May 3, 2023 · 2 comments · Fixed by #1704

Comments

@matheusvellone
Copy link
Contributor

When creating a child logger, looks like it isn't receiving all types from parent instance when the child method is called without any additional options, despite the call for custom levels being typed correctly.

I made a small code to reproduce the error here https://codesandbox.io/s/tender-river-42vrrt?file=/src/index.ts

But this is the code too, for a quick look

import pino from "pino";

const customLevels = {
  foo: 99
};

const logger = pino({
  customLevels
});

type Logger = typeof logger;
type LogLevels = pino.Level | keyof typeof customLevels;

const fn = (logger: Pick<Logger, LogLevels>) => {};

const child = logger.child({ name: "child" });
const child2 = logger.child({ name: "child" }, {}); // note extra {} here

fn(child); // missing foo typing
fn(child2);

child.foo("bar");
child2.foo("bar");

I tried adding a default type for this generic as a {} and it solved the problem. I suspect that the Options & ChildOptions ends in { ... } & undefined which evaluates to never 🤔

Not 100% sure if this is the expected solution, but I'd be happy to work on a PR

@mcollina
Copy link
Member

mcollina commented May 3, 2023

Go for the PR, sounds like a bug in the types

@github-actions
Copy link

github-actions bot commented Jun 4, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants