Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 6 commits intotypescript-eslint:masterfromsunghyunjo:issue/#2506
Oct 18, 2020

Conversation

@sunghyunjo
Copy link
Contributor

Fixes#2506

@typescript-eslint
Copy link
Contributor

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 onhttps://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day.

@codecov
Copy link

codecovbot commentedOct 2, 2020
edited
Loading

Codecov Report

Merging#2628 intomaster willincrease coverage by0.00%.
The diff coverage isn/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
FlagCoverage Δ
#unittest92.82% <ø> (+<0.01%)⬆️

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

Impacted FilesCoverage Δ
.../eslint-plugin/src/rules/restrict-plus-operands.ts100.00% <ø> (ø)

@bradzacherbradzacher added the enhancement: plugin rule optionNew rule option for an existing eslint-plugin rule labelOct 2, 2020
Copy link
Member

@bradzacherbradzacher left a 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!

Comment on lines +73 to +76
if(type.isIntersection()){
consttypes=type.types.map(getBaseTypeOfLiteralType);
returntypes.some(value=>value==='string') ?'string' :'invalid';
}
Copy link
Member

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 likeunknown & string, typescript tells us the type is juststring!
And for bad cases likenumber & string, typescript again tells us the type is justnever!

This is pretty awesome! 😄

papb and sunghyunjo reacted with thumbs up emoji
@bradzacherbradzacher merged commitda71362 intotypescript-eslint:masterOct 18, 2020
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsNov 18, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@bradzacherbradzacherbradzacher approved these changes

+1 more reviewer

@tadhgmistertadhgmistertadhgmister approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

enhancement: plugin rule optionNew rule option for an existing eslint-plugin rule

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[restrict-plus-operands] false positive on types like{} & string

3 participants

@sunghyunjo@bradzacher@tadhgmister

[8]ページ先頭

©2009-2025 Movatter.jp