-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[restrict-plus-operands] false positive on types like {} & string
#2506
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
Comments
That's not strictly true. The only cases that it holds true are: The cases of This rule just hasn't had it added. There's some prior art in the |
I will try this! |
@sunghyunjo Awesome!! |
@bradzacher Is this correct approach, or does it need to be fixed by modifying the existing I am suddenly confused and ask a question. Sorry for the delay. |
A new rule isn't a good idea to solve this problem. The problem isn't that people are able to create these branded types, the problem is that this rule doesn't support them. Supporting them should be pretty straightforward. You can use restrict-template-expressions for inspiration here. It has handling built in for branded types and does similar checks to this rule. |
Repro
Expected Result
No error
Actual Result
Additional Info
The minimal example above might seem nonsense, using
{} & string
, but it's to be minimal. I encountered a situation in real code involving complex type inferences in which one of the operands apparently ended up being inferred asstring | (Buffer & string)
(which also seems nonsense, maybe I should open an issue at TS too... Regardless,WhateverType & string
is a string, so the linter shouldn't complain).Versions
@typescript-eslint/eslint-plugin
3.10.1
4.0.1
@typescript-eslint/parser
3.10.1
4.0.1
TypeScript
4.0.2
4.0.2
ESLint
7.7.0
7.8.1
node
12.14.1
12.14.1
The text was updated successfully, but these errors were encountered: