Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fix(scope-manager): correctly handle inferred types in nested type sc…
…opes (#2497)
- Loading branch information
Showing
with
451 additions
and 0 deletions.
- +14 −0 packages/eslint-plugin/tests/rules/no-unused-vars.test.ts
- +39 −0 packages/scope-manager/src/referencer/TypeVisitor.ts
- +1 −0 packages/scope-manager/tests/fixtures/type-declaration/conditional3.ts
- +131 −0 packages/scope-manager/tests/fixtures/type-declaration/conditional3.ts.shot
- +1 −0 packages/scope-manager/tests/fixtures/type-declaration/conditional4.ts
- +106 −0 packages/scope-manager/tests/fixtures/type-declaration/conditional4.ts.shot
- +3 −0 packages/scope-manager/tests/fixtures/type-declaration/conditional5.ts
- +156 −0 packages/scope-manager/tests/fixtures/type-declaration/conditional5.ts.shot
@@ -0,0 +1 @@ | ||
type Test<U> = U extends (k: infer I) => void ? I : never; |
@@ -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, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
@@ -0,0 +1 @@ | ||
type Test<U> = U extends { [k: string]: infer I } ? I : never; |
@@ -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, | ||
], | ||
}, | ||
], | ||
} | ||
`; |
@@ -0,0 +1,3 @@ | ||
type Test<U> = U extends (arg: { [k: string]: (arg2: infer I) => void }) => void | ||
? I | ||
: never; |
Oops, something went wrong.