-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [restrict-plus-operands] add intersection type determination logic #2628
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
Conversation
Thanks for the PR, @sunghyunjo! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
Codecov Report
@@ Coverage Diff @@
## master #2628 +/- ##
=======================================
Coverage 92.82% 92.82%
=======================================
Files 293 293
Lines 9619 9622 +3
Branches 2697 2698 +1
=======================================
+ Hits 8929 8932 +3
Misses 326 326
Partials 364 364
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm - thanks for your contribution!
if (type.isIntersection()) { | ||
const types = type.types.map(getBaseTypeOfLiteralType); | ||
return types.some(value => value === 'string') ? 'string' : 'invalid'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it took me a second to figure out why this works for valid cases.
For the weird cases we care about (like {} & string
), typescript tells us the type is an intersection type.
For other cases like unknown & string
, typescript tells us the type is just string
!
And for bad cases like number & string
, typescript again tells us the type is just never
!
This is pretty awesome! 😄
Fixes #2506