Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
Repro
Enable the rule (seedocs)
Either
- Create a js file where numbers or strings are added
exportconstf=(a,b)=>a+b;
- Create a ts file, where arguments of type any are added
exportconstf=(a:any,b:any)=>a+b;
Observe the following error in each case:
Operands of '+' operation must either be both strings or both numbers.eslint(@typescript-eslint/restrict-plus-operands)
.eslintrc.js
{"rules": {"@typescript-eslint/restrict-plus-operands":"error" }}
Expected Result
The current result is fine, however too much strictness out of which you cannot opt out may get the rule challenging to use in existing codebases. I just tried enabling it in a monorepo with mixed js and ts code and got hundreds of errors. I understand the value behind this, just find it impossible to start using the rule to catch real issues (variable of known typenumber
being added to a variable of known typestring
). Errors in js files are especially unfortunate.
Would it be possible to optionally allowany
in the rule?
"@typescript-eslint/restrict-plus-operands": ["error", { allowAny: true }]
or even
"@typescript-eslint/restrict-plus-operands": ["error", { skipJs: true }]"@typescript-eslint/restrict-plus-operands": ["error", { allowAny: true, skipJs: true }]
Or should js files just be always skipped?
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin | 1.5.0 |
@typescript-eslint/parser | 1.5.0 |
TypeScript | 3.3.4000 |
ESLint | 5.15.3 |
node | 10.15.2 |
yarn | 1.13.0 |