-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(scope-manager): correct analysis of inferred types in conditional types #2537
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
90b431a
fix: #2526
dinofx 677582f
Update packages/scope-manager/src/referencer/TypeVisitor.ts
dinofx 29baa0b
Merge branch 'master' into master
dinofx a264cf9
Added fixture and snapshot
dinofx 5159409
Merge branch 'master' into master
dinofx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/scope-manager/tests/fixtures/type-declaration/conditional-nested.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type Test<T> = T extends Array<infer U> | ||
? U | ||
: T extends Set<infer U> | ||
? U | ||
: never; |
170 changes: 170 additions & 0 deletions
170
packages/scope-manager/tests/fixtures/type-declaration/conditional-nested.ts.shot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`type-declaration conditional-nested 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2 { | ||
defs: Array [ | ||
TypeDefinition$1 { | ||
name: Identifier<"Test">, | ||
node: TSTypeAliasDeclaration$1, | ||
}, | ||
], | ||
name: "Test", | ||
references: Array [], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
Variable$3 { | ||
defs: Array [ | ||
TypeDefinition$2 { | ||
name: Identifier<"T">, | ||
node: TSTypeParameter$2, | ||
}, | ||
], | ||
name: "T", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"T">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: Variable$3, | ||
}, | ||
Reference$4 { | ||
identifier: Identifier<"T">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: Variable$3, | ||
}, | ||
], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
Variable$4 { | ||
defs: Array [ | ||
TypeDefinition$3 { | ||
name: Identifier<"U">, | ||
node: TSTypeParameter$3, | ||
}, | ||
], | ||
name: "U", | ||
references: Array [ | ||
Reference$3 { | ||
identifier: Identifier<"U">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: Variable$4, | ||
}, | ||
], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
Variable$5 { | ||
defs: Array [ | ||
TypeDefinition$4 { | ||
name: Identifier<"U">, | ||
node: TSTypeParameter$4, | ||
}, | ||
], | ||
name: "U", | ||
references: Array [ | ||
Reference$6 { | ||
identifier: Identifier<"U">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: Variable$5, | ||
}, | ||
], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$5, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"const" => ImplicitGlobalConstTypeVariable, | ||
"Test" => Variable$2, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
ImplicitGlobalConstTypeVariable, | ||
Variable$2, | ||
], | ||
}, | ||
TypeScope$2 { | ||
block: TSTypeAliasDeclaration$1, | ||
isStrict: true, | ||
references: Array [], | ||
set: Map { | ||
"T" => Variable$3, | ||
}, | ||
type: "type", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$3, | ||
], | ||
}, | ||
ConditionalTypeScope$3 { | ||
block: TSConditionalType$6, | ||
isStrict: true, | ||
references: Array [ | ||
Reference$1, | ||
Reference$2 { | ||
identifier: Identifier<"Array">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: null, | ||
}, | ||
Reference$3, | ||
], | ||
set: Map { | ||
"U" => Variable$4, | ||
}, | ||
type: "conditionalType", | ||
upper: TypeScope$2, | ||
variables: Array [ | ||
Variable$4, | ||
], | ||
}, | ||
ConditionalTypeScope$4 { | ||
block: TSConditionalType$7, | ||
isStrict: true, | ||
references: Array [ | ||
Reference$4, | ||
Reference$5 { | ||
identifier: Identifier<"Set">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: null, | ||
}, | ||
Reference$6, | ||
], | ||
set: Map { | ||
"U" => Variable$5, | ||
}, | ||
type: "conditionalType", | ||
upper: TypeScope$2, | ||
variables: Array [ | ||
Variable$5, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.