8000 fix(scope-manager): allow visiting of constraint in infer type (#5331) · joshhunt/typescript-eslint@b2846a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit b2846a1

Browse files
authored
fix(scope-manager): allow visiting of constraint in infer type (typescript-eslint#5331)
1 parent c3f199a commit b2846a1

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ packages/ast-spec/src/*/*/fixtures/_error_/*/fixture.ts
1616

1717
# Syntax not yet supported
1818
packages/scope-manager/tests/fixtures/type-declaration/type-query-with-parameters.ts
19+
packages/scope-manager/tests/fixtures/type-declaration/infer-type-constraint.ts
1920

2021
# Ignore CHANGELOG.md files to avoid issues with automated release job
2122
CHANGELOG.md

packages/scope-manager/src/referencer/TypeVisitor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ class TypeVisitor extends Visitor {
167167
typeParameter.name,
168168
new TypeDefinition(typeParameter.name, typeParameter),
169169
);
170+
171+
this.visit(typeParameter.constraint);
170172
}
171173

172174
protected TSInterfaceDeclaration(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type X = string | number;
2+
type Id<T> = T extends { id: infer Id extends X } ? Id : never;
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`type-declaration infer-type-constraint 1`] = `
4+
ScopeManager {
5+
variables: Array [
6+
ImplicitGlobalConstTypeVariable,
7+
Variable$2 {
8+
defs: Array [
9+
TypeDefinition$1 {
10+
name: Identifier<"X">,
11+
node: TSTypeAliasDeclaration$1,
12+
},
13+
],
14+
name: "X",
15+
references: Array [
16+
Reference$2 {
17+
identifier: Identifier<"X">,
18+
isRead: true,
19+
isTypeReference: true,
20+
isValueReference: false,
21+
isWrite: false,
22+
resolved: Variable$2,
23+
},
24+
],
25+
isValueVariable: false,
26+
isTypeVariable: true,
27+
},
28+
Variable$3 {
29+
defs: Array [
30+
TypeDefinition$2 {
31+
name: Identifier<"Id">,
32+
node: TSTypeAliasDeclaration$2,
33+
},
34+
],
35+
name: "Id",
36+
references: Array [],
37+
isValueVariable: false,
38+
isTypeVariable: true,
39+
},
40+
Variable$4 {
41+
defs: Array [
42+
TypeDefinition$3 {
43+
name: Identifier<"T">,
44+
node: TSTypeParameter$3,
45+
},
46+
],
47+
name: "T",
48+
references: Array [
49+
Reference$1 {
50+
identifier: Identifier<"T">,
51+
isRead: true,
52+
isTypeReference: true,
53+
isValueReference: false,
54+
isWrite: false,
55+
resolved: Variable$4,
56+
},
57+
],
58+
isValueVariable: false,
59+
isTypeVariable: true,
60+
},
61+
Variable$5 {
62+
defs: Array [
63+
TypeDefinition$4 {
64+
name: Identifier<"Id">,
65+
node: TSTypeParameter$4,
66+
},
67+
],
68+
name: "Id",
69+
references: Array [
70+
Reference$3 {
71+
identifier: Identifier<"Id">,
72+
isRead: true,
73+
isTypeReference: true,
74+
isValueReference: false,
75+
isWrite: false,
76+
resolved: Variable$5,
77+
},
78+
],
79+
isValueVariable: false,
80+
isTypeVariable: true,
81+
},
82+
],
83+
scopes: Array [
84+
GlobalScope$1 {
85+
block: Program$5,
86+
isStrict: false,
87+
references: Array [],
88+
set: Map {
89+
"const" => ImplicitGlobalConstTypeVariable,
90+
"X" => Variable$2,
91+
"Id" => Variable$3,
92+
},
93+
type: "global",
94+
upper: null,
95+
variables: Array [
96+
ImplicitGlobalConstTypeVariable,
97+
Variable$2,
98+
Variable$3,
99+
],
100+
},
101+
TypeScope$2 {
102+
block: TSTypeAliasDeclaration$2,
103+
isStrict: true,
104+
references: Array [],
105+
set: Map {
106+
"T" => Variable$4,
107+
},
108+
type: "type",
109+
upper: GlobalScope$1,
110+
variables: Array [
111+
Variable$4,
112+
],
113+
},
114+
ConditionalTypeScope$3 {
115+
block: TSConditionalType$6,
116+
isStrict: true,
117+
references: Array [
118+
Reference$1,
119+
Reference$2,
120+
Reference$3,
121+
],
122+
set: Map {
123+
"Id" => Variable$5,
124+
},
125+
type: "conditionalType",
126+
upper: TypeScope$2,
127+
variables: Array [
128+
Variable$5,
129+
],
130+
},
131+
],
132+
}
133+
`;

0 commit comments

Comments
 (0)
0