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

@typescript-eslint typescript-eslint bot commented Sep 10, 2020

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 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
@dinofx dinofx force-pushed the dinofx:master branch from a0f619a to 90b431a Sep 10, 2020
@bradzacher bradzacher added the bug label Sep 12, 2020
Copy link
Member

@bradzacher bradzacher left a comment

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.

dinofx and others added 3 commits Sep 14, 2020
Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
@dinofx dinofx requested a review from bradzacher Sep 14, 2020
@dinofx
Copy link
Contributor Author

@dinofx dinofx commented Sep 14, 2020

Added the new fixture and snapshot

@dinofx
Copy link
Contributor Author

@dinofx dinofx commented Sep 16, 2020

@bradzacher are any other changes needed?

Copy link
Member

@bradzacher bradzacher left a comment

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
10 checks passed
10 checks passed
Typecheck
Details
Unit tests Unit tests
Details
Code style and lint
Details
Run integration tests on primary Node.js version
Details
Run unit tests on other Node.js versions (10.x)
Details
Run unit tests on other Node.js versions (14.x)
Details
Publish the latest code as a canary version
Details
Semantic Pull Request ready to be squashed
Details
codecov/patch Codecov Report
Details
codecov/project Codecov Report
Details
phaux added a commit to phaux/typescript-eslint that referenced this pull request Sep 28, 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.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants