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

Fix bugs in createLogger type #1807

Merged
merged 2 commits into from
Jun 22, 2020
Merged

Conversation

Mizumaki
Copy link
Contributor

There is a lack of type correctness, and it causes TypeScript error when we set levels option.
This PR aims to fix it.

Problem

We can set levels option in createLogger. For this option, you can use any string as a log level.

However, in the type world, it wasn't accepted.

スクリーンショット 2020-06-11 22 05 00

Additionally, there is more bug in here.

Following the implementation, if we set the levels option, the default levels options are overridden. However, in type world, it was accepted.

スクリーンショット 2020-06-11 22 13 13

After this PR

Works with levels option.

スクリーンショット 2020-06-11 22 18 04

Of course, without levels option, default levels are inferred correctly.

スクリーンショット 2020-06-11 22 18 38

@Mizumaki Mizumaki changed the title Fix createLogger type Fix bugs in createLogger type Jun 11, 2020
@Mizumaki Mizumaki marked this pull request as ready for review June 11, 2020 13:39
Copy link
Contributor

@DABH DABH left a comment

Choose a reason for hiding this comment

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

This is a clever approach and it does look like it solves the mentioned issues. It would be great to get some Typescript tests going for winston at some point since there are so many TS users. Meanwhile I will merge this, thank you for the contribution!

@DABH DABH merged commit ef97171 into winstonjs:master Jun 22, 2020
notice: number;
}

type Logger<T extends Config.AbstractConfigSetLevels = DefaulLevels> = NodeJSStream.Transform & {

Choose a reason for hiding this comment

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

To prevent any breaking changes, generic should be T extends Config.AbstractConfigSetLevels = DefaultLevels | Config.AbstractConfigSetLevels

Mizumaki added a commit to Mizumaki/winston that referenced this pull request Jun 23, 2020
@Mizumaki Mizumaki mentioned this pull request Jun 23, 2020
DABH pushed a commit that referenced this pull request Jun 23, 2020
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

Successfully merging this pull request may close these issues.

None yet

3 participants