-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(scope-manager): correctly handle inferred types in nested type sc…
…opes (#2497)
- Loading branch information
1 parent
4d3ce5f
commit 95f6bf4
Showing
8 changed files
with
451 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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
1 change: 1 addition & 0 deletions
1
packages/scope-manager/tests/fixtures/type-declaration/conditional3.ts
This file contains 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 @@ | ||
type Test<U> = U extends (k: infer I) => void ? I : never; |
131 changes: 131 additions & 0 deletions
131
packages/scope-manager/tests/fixtures/type-declaration/conditional3.ts.shot
This file contains 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,131 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`type-declaration conditional3 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
Variable$1 { | ||
defs: Array [ | ||
TypeDefinition$1 { | ||
name: Identifier<"Test">, | ||
node: TSTypeAliasDeclaration$1, | ||
}, | ||
], | ||
name: "Test", | ||
references: Array [], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
Variable$2 { | ||
defs: Array [ | ||
TypeDefinition$2 { | ||
name: Identifier<"U">, | ||
node: TSTypeParameter$2, | ||
}, | ||
], | ||
name: "U", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"U">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: Variable$2, | ||
}, | ||
], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
Variable$3 { | ||
defs: Array [ | ||
ParameterDefinition$3 { | ||
name: Identifier<"k">, | ||
node: TSFunctionType$3, | ||
}, | ||
], | ||
name: "k", | ||
references: Array [], | ||
isValueVariable: true, | ||
isTypeVariable: false, | ||
}, | ||
Variable$4 { | ||
defs: Array [ | ||
TypeDefinition$4 { | ||
name: Identifier<"I">, | ||
node: TSTypeParameter$4, | ||
}, | ||
], | ||
name: "I", | ||
references: Array [ | ||
Reference$2 { | ||
identifier: Identifier<"I">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: Variable$4, | ||
}, | ||
], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$5, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"Test" => Variable$1, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
Variable$1, | ||
], | ||
}, | ||
TypeScope$2 { | ||
block: TSTypeAliasDeclaration$1, | ||
isStrict: true, | ||
references: Array [], | ||
set: Map { | ||
"U" => Variable$2, | ||
}, | ||
type: "type", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$2, | ||
], | ||
}, | ||
ConditionalTypeScope$3 { | ||
block: TSConditionalType$6, | ||
isStrict: true, | ||
references: Array [ | ||
Reference$1, | ||
Reference$2, | ||
], | ||
set: Map { | ||
"I" => Variable$4, | ||
}, | ||
type: "conditionalType", | ||
upper: TypeScope$2, | ||
variables: Array [ | ||
Variable$4, | ||
], | ||
}, | ||
FunctionTypeScope$4 { | ||
block: TSFunctionType$3, | ||
isStrict: true, | ||
references: Array [], | ||
set: Map { | ||
"k" => Variable$3, | ||
}, | ||
type: "functionType", | ||
upper: ConditionalTypeScope$3, | ||
variables: Array [ | ||
Variable$3, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
1 change: 1 addition & 0 deletions
1
packages/scope-manager/tests/fixtures/type-declaration/conditional4.ts
This file contains 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 @@ | ||
type Test<U> = U extends { [k: string]: infer I } ? I : never; |
106 changes: 106 additions & 0 deletions
106
packages/scope-manager/tests/fixtures/type-declaration/conditional4.ts.shot
This file contains 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,106 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`type-declaration conditional4 1`] = ` | ||
ScopeManager { | ||
variables: Array [ | ||
Variable$1 { | ||
defs: Array [ | ||
TypeDefinition$1 { | ||
name: Identifier<"Test">, | ||
node: TSTypeAliasDeclaration$1, | ||
}, | ||
], | ||
name: "Test", | ||
references: Array [], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
Variable$2 { | ||
defs: Array [ | ||
TypeDefinition$2 { | ||
name: Identifier<"U">, | ||
node: TSTypeParameter$2, | ||
}, | ||
], | ||
name: "U", | ||
references: Array [ | ||
Reference$1 { | ||
identifier: Identifier<"U">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: Variable$2, | ||
}, | ||
], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
Variable$3 { | ||
defs: Array [ | ||
TypeDefinition$3 { | ||
name: Identifier<"I">, | ||
node: TSTypeParameter$3, | ||
}, | ||
], | ||
name: "I", | ||
references: Array [ | ||
Reference$2 { | ||
identifier: Identifier<"I">, | ||
isRead: true, | ||
isTypeReference: true, | ||
isValueReference: false, | ||
isWrite: false, | ||
resolved: Variable$3, | ||
}, | ||
], | ||
isValueVariable: false, | ||
isTypeVariable: true, | ||
}, | ||
], | ||
scopes: Array [ | ||
GlobalScope$1 { | ||
block: Program$4, | ||
isStrict: false, | ||
references: Array [], | ||
set: Map { | ||
"Test" => Variable$1, | ||
}, | ||
type: "global", | ||
upper: null, | ||
variables: Array [ | ||
Variable$1, | ||
], | ||
}, | ||
TypeScope$2 { | ||
block: TSTypeAliasDeclaration$1, | ||
isStrict: true, | ||
references: Array [], | ||
set: Map { | ||
"U" => Variable$2, | ||
}, | ||
type: "type", | ||
upper: GlobalScope$1, | ||
variables: Array [ | ||
Variable$2, | ||
], | ||
}, | ||
ConditionalTypeScope$3 { | ||
block: TSConditionalType$5, | ||
isStrict: true, | ||
references: Array [ | ||
Reference$1, | ||
Reference$2, | ||
], | ||
set: Map { | ||
"I" => Variable$3, | ||
}, | ||
type: "conditionalType", | ||
upper: TypeScope$2, | ||
variables: Array [ | ||
Variable$3, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
3 changes: 3 additions & 0 deletions
3
packages/scope-manager/tests/fixtures/type-declaration/conditional5.ts
This file contains 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,3 @@ | ||
type Test<U> = U extends (arg: { [k: string]: (arg2: infer I) => void }) => void | ||
? I | ||
: never; |
Oops, something went wrong.