Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[restrict-plus-operands] Valid number and bigint intersections aren't supported in the restrict-plus-operands rule #4798

Closed
3 tasks done
leonsilicon opened this issue Apr 8, 2022 · 1 comment · Fixed by #4795
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@leonsilicon
Copy link
Contributor

leonsilicon commented Apr 8, 2022

Related PR: #4795 (review)

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "@typescript-eslint/restrict-plus-operands": ["error"]
  }
}
const a = 'string' as string & { foo: 'bar' }
const b = 42 as number & { foo: 'bar' };
const c = 42n as bigint & { foo: 'bar' };

console.log(a + 'string')
console.log(b + 42);
console.log(c + 42n);

Playground link: https://typescript-eslint.io/play/#ts=4.6.2&sourceType=module&code=MYewdgzgLgBAhjAvDA5NATgSzAcxfCGDbHGAMhgG8YAzEEALlQCM518BfAKFElmaQwALACYCMMAFcAtswCm6clVr0mKVuxgcA3D3DQYwQaLDjmmHNlgVqdRizaddeyCAA2cgHRuQOABQIANSoxLgoAJQuEO5ePv4CwaLhurzRHt6+fkaJImDJXEA&rules=N4IgAgLgngDgpgZwMYCcCWMIFpEBs0B2EA9CohOktjLgK4JYD28KAhgQCYIgBcIcKFIxQgAvkA&tsConfig=N4XyA

Expected Result
No linting error on lines 6 and 7, as the rule restrict-plus-operands doesn't error when there is a valid string intersection but errors with valid number and bigint intersections.

Actual Result

Error on line 6: Operands of '+' operation must either be both strings or both numbers.ESLint(@typescript-eslint/restrict-plus-operands)
Error on line 7: Operands of '+' operation must be both bigints.ESLint(@typescript-eslint/restrict-plus-operands)

Additional Info

Real-world use case: vuejs/eslint-plugin-vue#1839 (comment)

Versions

package version
@typescript-eslint/eslint-plugin 5.18.0
@typescript-eslint/parser 5.18.0
TypeScript 4.6.2
ESLint 8.7.0
node N/A
@leonsilicon leonsilicon added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Apr 8, 2022
@JoshuaKGoldberg
Copy link
Member

Super, thanks for the additional context. This makes sense!

@bradzacher bradzacher added bug Something isn't working accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Apr 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants