Add literal types and values for logger levels#2056
Open
mb-realpage wants to merge 2 commits intohandlebars-lang:4.xfrom
Open
Add literal types and values for logger levels#2056mb-realpage wants to merge 2 commits intohandlebars-lang:4.xfrom
mb-realpage wants to merge 2 commits intohandlebars-lang:4.xfrom
Conversation
By default, `logger.level` is set to "info," type: `string`, even though types/index.d.ts specifies that `level` should be type: `number`. This is confusing. Worse, setting `logger.level` in TypeScript will not allow a string to be used. A specific number must be provided, even though a string works because `lookupLevel` converts the given string to the correct number. So setting `logger.level` must be done in one of two unsatisfactory ways: * By using double assertion to lie to TypeScript, i.e., using a string with `as unknown as number`. This defeats the purpose of types. * By providing the exact index of the log level desired, which requires reading Handlebars' logger implementation to see that: * `debug` = 0 * `info` = 1 * `warn` = 2 * `error` = 3 Note that these numbers are not available in the keys that are defined in the types (`DEBUG`, `INFO`, `WARN`, and `ERROR`), since they are not actually defined in the logger itself.
The types for `DEBUG`, `INFO`, `WARN`, and `ERROR` are present in the types `logger`, but not in the code. If they're in the types they should be in the code as well.
4 tasks
Author
|
@jaylinski Can you review this pull request? |
Member
Author
|
@jaylinski So sorry, I just saw your message. I'll look into adding tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before creating a pull-request, please check https://github.com/handlebars-lang/handlebars.js/blob/master/CONTRIBUTING.md first.
Generally we like to see pull requests that
4.x-branch contains the latest version. Please target that branch in the PR.Note: fixes #2055