@@ -156,7 +156,21 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
156156 }
157157 }
158158
159- forEachNode ( ast , ( node : AugmentedNode ) => {
159+ // Number of conditional type expressions the visitor is currently inside.
160+ // We disable type extraction inside such type expressions, to avoid complications
161+ // with `infer` types.
162+ let insideConditionalTypes = 0 ;
163+
164+ visitAstNode ( ast ) ;
165+ function visitAstNode ( node : AugmentedNode ) {
166+ if ( node . kind === ts . SyntaxKind . ConditionalType ) {
167+ ++ insideConditionalTypes ;
168+ }
169+ ts . forEachChild ( node , visitAstNode ) ;
170+ if ( node . kind === ts . SyntaxKind . ConditionalType ) {
171+ -- insideConditionalTypes ;
172+ }
173+
160174 // fill in line/column info
161175 if ( "pos" in node ) {
162176 node . $pos = augmentPos ( node . pos , true ) ;
@@ -176,7 +190,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
176190 }
177191 }
178192
179- if ( typeChecker != null ) {
193+ if ( typeChecker != null && insideConditionalTypes === 0 ) {
180194 if ( isTypedNode ( node ) ) {
181195 let contextualType = isContextuallyTypedNode ( node )
182196 ? typeChecker . getContextualType ( node )
@@ -250,7 +264,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
250264 }
251265 }
252266 }
253- } ) ;
267+ }
254268}
255269
256270type NamedNodeWithSymbol = AugmentedNode & ( ts . ClassDeclaration | ts . InterfaceDeclaration
0 commit comments