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

Incorrect type for logger.level #2055

Open
4 tasks done
mb-realpage opened this issue Nov 23, 2024 · 1 comment
Open
4 tasks done

Incorrect type for logger.level #2055

mb-realpage opened this issue Nov 23, 2024 · 1 comment

Comments

@mb-realpage
Copy link

mb-realpage commented Nov 23, 2024

Before filing issues, please check the following points first:

This will probably help you to get a solution faster.
For bugs, it would be great to have a PR with a failing test-case.

For usability, the types for logger are not good. logger.level is specifically typed as number, and only number, not number | string. But then logger.level is initialized as a string. This is confusing.

Worse, logger.ERROR, logger.WARN, logger.INFO, and logger.DEBUG are typed, but they do not map to any value. They look like constants to be used in your own code, but they are undefined.

This means there are two ways to set Handlebars' log level, both unappealing:

  • Ignore the clear typing of logger.level and set it to a string anyway, which will throw TypeScript errors but work. Override this by miscasting, i.e., as unknown as number.
  • Dig into Handlebars' code directly and manually map level names to the indexes of the level names in logger.methodMap. These are the values we might expect logger.ERROR, logger.WARN, etc. to represent, but they don't.

To my mind, logger.level should definitely be typed as number | string at the very least, or better yet, number | 'error' | 'warn' | 'info' | 'debug'. And the constants should be hardcoded or at least set when Handlebars starts.

@mb-realpage
Copy link
Author

PR: #2056

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

No branches or pull requests

1 participant