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

feat(eslint-plugin): [restrict-plus-operands] add intersection type determination logic #2628

merged 6 commits into from Oct 18, 2020


Copy link

@sunghyunjo sunghyunjo commented Oct 2, 2020

Fixes #2506

Copy link

@typescript-eslint typescript-eslint bot commented Oct 2, 2020

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 As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

Copy link

@codecov codecov bot commented Oct 2, 2020

Codecov Report

Merging #2628 into master will increase coverage by 0.00%.
The diff coverage is n/a.

@@           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           
Flag Coverage Δ
#unittest 92.82% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../eslint-plugin/src/rules/restrict-plus-operands.ts 100.00% <ø> (ø)
Copy link

@bradzacher bradzacher left a comment

lgtm - thanks for your contribution!

if (type.isIntersection()) {
const types =;
return types.some(value => value === 'string') ? 'string' : 'invalid';
Comment on lines +73 to +76

This comment has been minimized.


bradzacher Oct 18, 2020

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! 😄

@bradzacher bradzacher merged commit da71362 into typescript-eslint:master Oct 18, 2020
10 checks passed
10 checks passed
Unit tests Unit tests
Code style and lint
Run integration tests on primary Node.js version
Run unit tests on other Node.js versions (10.x)
Run unit tests on other Node.js versions (14.x)
Publish the latest code as a canary version
Semantic Pull Request ready to be squashed
codecov/patch Codecov Report
codecov/project Codecov Report
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants
You can’t perform that action at this time.