Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I havesearched for related issues and found none that match my proposal.
- I have searched thecurrent rule list and found no rules that match my proposal.
- I haveread the FAQ and my problem is not listed.
My proposal is suitable for this project
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Link to the rule's documentation
https://typescript-eslint.io/rules/restrict-plus-operands
Description
restrict-plus-operands andrestrict-template-expressions don't tackle the exact same JavaScript behaviors (+ operands and template expressions don't concatenate/toString()/toValue() quite the same). But they both generally tackle the specific common case of code trying to join a string with a non-string:
''+0;''+{};// _roughly_ equivalent to:`${0}`;`${{}}`;
As a user, I've been inconvenienced byrestrict-plus-operands complaining on concatenating two primitive values: e.g.number andstring. Sometimes I want to be able to join primitives together in my logs!
Proposal: can we add the following options that already exist inrestrict-template-expressions?
: already exists!allowAnyallowNumberallowBooleanallowNullishallowRegExp
Fail
''+{}
Pass
''+0
Additional Info
I think we've seen a bigger demand for them inrestrict-template-expressions because ofhttps://eslint.org/docs/latest/rules/prefer-template. Linted projects don't concatenate strings with+ as much as they used to.