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

fix(scope-manager): correct analysis of inferred types in conditional types #2537

Merged
merged 5 commits into from Sep 16, 2020

Conversation

dinofx
Copy link
Contributor

@dinofx dinofx commented Sep 10, 2020

This fixes #2526
In a conditional type, the inferred types are not in scope in the "if false" type.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @dinofx!

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
Copy link

codecov bot commented Sep 10, 2020

Codecov Report

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

@@           Coverage Diff           @@
##           master    #2537   +/-   ##
=======================================
  Coverage   92.82%   92.82%           
=======================================
  Files         290      290           
  Lines        9505     9506    +1     
  Branches     2664     2664           
=======================================
+ Hits         8823     8824    +1     
  Misses        323      323           
  Partials      359      359           
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 Δ
...ckages/scope-manager/src/referencer/TypeVisitor.ts 89.13% <ø> (+0.11%) ⬆️

@dinofx dinofx changed the title fix(eslint-plugin): [no-shadow] false positive in conditional types fix(eslint-plugin): [no-shadow] false positive in conditional types fix:2526 Sep 10, 2020
@dinofx dinofx changed the title fix(eslint-plugin): [no-shadow] false positive in conditional types fix:2526 fix(eslint-plugin): [no-shadow] false positive in conditional types fix:#2526 Sep 10, 2020
@bradzacher bradzacher added the bug Something isn't working label Sep 12, 2020
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix itself LGTM!


To help prevent regressions, could you please add a new snapshot test into packages/scope-manager/tests/fixtures/type-declaration
Call it something like conditional-nested.ts

The test should be something like:

type Test<T> = T extends Array<infer U>
  ? U
  : T extends Set<infer U>
  ? U

Then you can cd pacakges/scope-manager && yarn test fixtures -u to update the snapshot.
What we're looking for here is a snapshot wherein there are two separate U variables created each with their own reference.

If you're not sure what to look for, just push the snapshot and I will be able to verify it.

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Sep 13, 2020
@dinofx
Copy link
Contributor Author

dinofx commented Sep 14, 2020

Added the new fixture and snapshot

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Sep 15, 2020
@dinofx
Copy link
Contributor Author

dinofx commented Sep 16, 2020

@bradzacher are any other changes needed?

Copy link
Member

@bradzacher bradzacher 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 doing this!

@bradzacher bradzacher changed the title fix(eslint-plugin): [no-shadow] false positive in conditional types fix:#2526 fix(scope-manager): correct analysis of inferred types in conditional types Sep 16, 2020
@bradzacher bradzacher merged commit 4f660fd into typescript-eslint:master Sep 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[@typescript-eslint/no-shadow] false positives with conditional types and infer
2 participants