Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read 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
and restrict-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 by restrict-plus-operands
complaining on concatenating two primitive values: e.g. number
and string
. Sometimes I want to be able to join primitives together in my logs!
Proposal: can we add the following options that already exist in restrict-template-expressions
?
: already exists!allowAny
allowNumber
allowBoolean
allowNullish
allowRegExp
Fail
'' + {}
Pass
'' + 0
Additional Info
I think we've seen a bigger demand for them in restrict-template-expressions
because of https://eslint.org/docs/latest/rules/prefer-template. Linted projects don't concatenate strings with +
as much as they used to.