-
Notifications
You must be signed in to change notification settings - Fork 889
Include actual types for restrict-plus-operands. #4635
Conversation
@bowenni can you take a look at this? |
I think the test failure is an infrastructure failure, but I cannot retry because I don't have permissions. |
I love this idea! Marked as accepting PRs. In the future @mprobst, please file an issue describing your requested changes before sending a PR that non-trivially changes TSLint. This one happens to be immediately acceptable but most aren't. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this in! Just one touchup on the failure text requested.
It can be difficult for users to find out why exactly they received the "restrict-plus-operands" lint error. In particular, users often end up with `any` types leaking into their code (e.g. in tests), and are then puzzled why this triggers. To fix, this change includes a textual representation of the type in the error message, e.g.: [Operands of '+' operation must either be both strings or both numbers, but found 5 + undefined[]] The type representation isn't always super pretty (e.g. the `undefined[]` bit above), but should still be helpful, and also matches TS compiler's representation of these.
Will do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic, thanks so much @mprobst! 🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @mprobst @JoshuaKGoldberg! I'll fix the build on master if it fails there.
It can be difficult for users to find out why exactly they received the
"restrict-plus-operands" lint error. In particular, users often end up
with
any
types leaking into their code (e.g. in tests), and are thenpuzzled why this triggers.
To fix, this change includes a textual representation of the type in the
error message, e.g.:
The type representation isn't always super pretty (e.g. the
undefined[]
bit above), but should still be helpful, and also matchesTS compiler's representation of these.
PR checklist
CHANGELOG.md entry:
[enhancement] Improve error message for
restrict-plus-operands
rule.