Fix getCodeFixesAtPosition for ts(2339) thows error False expression: Token end is child end (#43645)

* Fix getCodeFixesAtPosition for ts(2339) thows error False expression: Token end is child end
Fixes #43191

* Add test
This commit is contained in:
Jean Pierre
2021-04-20 12:00:34 -05:00
committed by GitHub
parent a910c8df13
commit 8513f78058
2 changed files with 66 additions and 2 deletions

View File

@@ -276,11 +276,11 @@ namespace ts.codefix {
const binaryExpression = token.parent.parent as BinaryExpression;
const otherExpression = token.parent === binaryExpression.left ? binaryExpression.right : binaryExpression.left;
const widenedType = checker.getWidenedType(checker.getBaseTypeOfLiteralType(checker.getTypeAtLocation(otherExpression)));
typeNode = checker.typeToTypeNode(widenedType, classDeclaration, /*flags*/ undefined);
typeNode = checker.typeToTypeNode(widenedType, classDeclaration, NodeBuilderFlags.NoTruncation);
}
else {
const contextualType = checker.getContextualType(token.parent as Expression);
typeNode = contextualType ? checker.typeToTypeNode(contextualType, /*enclosingDeclaration*/ undefined, /*flags*/ undefined) : undefined;
typeNode = contextualType ? checker.typeToTypeNode(contextualType, /*enclosingDeclaration*/ undefined, NodeBuilderFlags.NoTruncation) : undefined;
}
return typeNode || factory.createKeywordTypeNode(SyntaxKind.AnyKeyword);
}