Skip to content

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

@leonsilicon

Description

@leonsilicon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy