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

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

Closed
Zamiell opened this issue Aug 12, 2023 · 5 comments · Fixed by #1783
Closed

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

Zamiell opened this issue Aug 12, 2023 · 5 comments · Fixed by #1783

Comments

@Zamiell
Copy link
Contributor

Zamiell commented Aug 12, 2023

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.

@jsumners
Copy link
Member

@Zamiell
Copy link
Contributor Author

Zamiell commented Aug 12, 2023

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.

@Zamiell
Copy link
Contributor Author

Zamiell commented Aug 12, 2023

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

I can submit a PR if needed.

@mcollina
Copy link
Member

Send it over, thanks!

Copy link

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 Jan 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants