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

[Bug]: type hints say there's a logger.warning() but it does not exist #2280

Closed
kosta opened this issue Feb 10, 2023 · 4 comments · Fixed by #2339
Closed

[Bug]: type hints say there's a logger.warning() but it does not exist #2280

kosta opened this issue Feb 10, 2023 · 4 comments · Fixed by #2339

Comments

@kosta
Copy link

kosta commented Feb 10, 2023

🔎 Search Terms

warning

The problem

index.d.ts claims Logger has a warning function. Calling that function leads to TypeError: logger.warning is not a function at ....

Please remove the wrong type hint, and potentially everything under // for syslog levels only?

What version of Winston presents the issue?

v3.8.2

What version of Node are you using?

v18.12.1

If this worked in a previous version of Winston, which was it?

No response

Minimum Working Example

Welcome to Node.js v18.12.1.
Type ".help" for more information.
> const winston = require('winston')
undefined
> const logger = winston.createLogger({})
undefined
> logger.warning("oops")
Uncaught TypeError: logger.warning is not a function

Additional information

No response

@wbt
Copy link
Contributor

wbt commented Feb 10, 2023

This probably affects all the rest of the syslog levels, not just warning.
However, adding a .warning() method aliasing .warn() seems like it could be a useful change to accompany #2277.
There's likely a way to do it with existing code user-side via custom log levels, but I'm not sure how well that works with types.

@JavaScriptBach
Copy link
Contributor

Is this project still being maintained? Would you be willing to accept a PR removing incorrect types and push a new release?

We just got bit by this in production, and it seems like a very urgent and easy fix.

@JavaScriptBach
Copy link
Contributor

@wbt I opened #2339

@codazzo
Copy link

codazzo commented Apr 2, 2024

As the code changes in the fix PR have been reverted (for good reason), this is what I will be resorting to in my current project in order to avoid this issue, which is unfortunately unresolved:

import winston from 'winston';

const logger = winston.createLogger() as Pick<
  winston.Logger,
  'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly'
>;

Given the polymorphic nature of the winston instance when it comes to log-level-specific method names, I don't know of a better way to address this.

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

Successfully merging a pull request may close this issue.

4 participants