Skip to content

fix: stricter type #1297

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

Merged
merged 3 commits into from
Jan 12, 2022
Merged

fix: stricter type #1297

merged 3 commits into from
Jan 12, 2022

Conversation

climba03003
Copy link
Contributor

@climba03003 climba03003 commented Jan 11, 2022

Fixes #1293

Notable Changes:

  • Remove Record<string, any> from Logger.
  • Update tsconfig.json, I think the current include should be exclude because it should not compile the test file which may contain error.
  • Reflect customLevels options and combine it with Logger.

I think it can provide even more stricter type on the options like useOnlyCustomLevels, level, etc. But it require a heavy refactor and times.

@climba03003
Copy link
Contributor Author

The CI failure is actually not related to my changes.

@@ -90,6 +91,7 @@ pino({
});

pino({ base: null });
// @ts-expect-error
if ("pino" in log) console.log(`pino version: ${log.pino}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why it is inside the type check.
I cannot find the relevant code in js.

@mcollina mcollina requested a review from kibertoad January 11, 2022 16:55
@mcollina
Copy link
Member

Should we update the doc?

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@climba03003
Copy link
Contributor Author

Should we update the doc?

I don't know which file is appropriate for the update. Currently, pino do not provide a TypeScript specific document.

@mcollina
Copy link
Member

Ah don't worry then. Let's just wait for @kibertoad.

Copy link
Contributor

@kibertoad kibertoad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@kibertoad kibertoad merged commit 5e31678 into pinojs:master Jan 12, 2022
@MaikuMori
Copy link

MaikuMori commented Jan 21, 2022

I believe that this broke something.

Basically, Logger<{customLevels}> is not carried over after logger.child() call and I get type error on the child instance when using a custom level function.

const logger = pino({
  customLevels: {
    warning: 400,
  },
  useOnlyCustomLevels: true,
});
const child = logger.child({whatever:true});
// Type error.
child.warning("Hello there");

This was not the case before.

EDIT:
TS version: 4.5.5

@github-actions
Copy link

This pull request 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 22, 2023
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 this pull request may close these issues.

TypeScript types do not provide expected safety
4 participants