TS: Workaround issue with infer types

This commit is contained in:
Asger F
2019-04-30 16:07:45 +01:00
parent 5c8dd7eedd
commit 15299aba7d

View File

@@ -156,7 +156,21 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
}
}
forEachNode(ast, (node: AugmentedNode) => {
// Number of conditional type expressions the visitor is currently inside.
// We disable type extraction inside such type expressions, to avoid complications
// with `infer` types.
let insideConditionalTypes = 0;
visitAstNode(ast);
function visitAstNode(node: AugmentedNode) {
if (node.kind === ts.SyntaxKind.ConditionalType) {
++insideConditionalTypes;
}
ts.forEachChild(node, visitAstNode);
if (node.kind === ts.SyntaxKind.ConditionalType) {
--insideConditionalTypes;
}
// fill in line/column info
if ("pos" in node) {
node.$pos = augmentPos(node.pos, true);
@@ -176,7 +190,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
}
}
if (typeChecker != null) {
if (typeChecker != null && insideConditionalTypes === 0) {
if (isTypedNode(node)) {
let contextualType = isContextuallyTypedNode(node)
? typeChecker.getContextualType(node)
@@ -250,7 +264,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
}
}
}
});
}
}
type NamedNodeWithSymbol = AugmentedNode & (ts.ClassDeclaration | ts.InterfaceDeclaration