@@ -154,7 +154,21 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
154
154
}
155
155
}
156
156
157
- forEachNode ( ast , ( node : AugmentedNode ) => {
157
+ // Number of conditional type expressions the visitor is currently inside.
158
+ // We disable type extraction inside such type expressions, to avoid complications
159
+ // with `infer` types.
160
+ let insideConditionalTypes = 0 ;
161
+
162
+ visitAstNode ( ast ) ;
163
+ function visitAstNode ( node : AugmentedNode ) {
164
+ if ( node . kind === ts . SyntaxKind . ConditionalType ) {
165
+ ++ insideConditionalTypes ;
166
+ }
167
+ ts . forEachChild ( node , visitAstNode ) ;
168
+ if ( node . kind === ts . SyntaxKind . ConditionalType ) {
169
+ -- insideConditionalTypes ;
170
+ }
171
+
158
172
// fill in line/column info
159
173
if ( "pos" in node ) {
160
174
node . $pos = augmentPos ( node . pos , true ) ;
@@ -174,7 +188,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
174
188
}
175
189
}
176
190
177
- if ( typeChecker != null ) {
191
+ if ( typeChecker != null && insideConditionalTypes === 0 ) {
178
192
if ( isTypedNode ( node ) ) {
179
193
let type = typeChecker . getTypeAtLocation ( node ) ;
180
194
if ( type != null ) {
@@ -245,7 +259,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
245
259
}
246
260
}
247
261
}
248
- } ) ;
262
+ }
249
263
}
250
264
251
265
type NamedNodeWithSymbol = AugmentedNode & ( ts . ClassDeclaration | ts . InterfaceDeclaration
0 commit comments