Fixed false positive circular errors for await expressions with simple non-generic calls in CFA loops (#51126)

This commit is contained in:
Mateusz Burzyński
2023-01-09 19:56:52 +01:00
committed by GitHub
parent 00567618bd
commit 2c1fda249f
10 changed files with 1036 additions and 17 deletions

View File

@@ -427,6 +427,7 @@ import {
isAssignmentTarget,
isAsyncFunction,
isAutoAccessorPropertyDeclaration,
isAwaitExpression,
isBinaryExpression,
isBindableObjectDefinePropertyCall,
isBindableStaticElementAccessExpression,
@@ -36482,7 +36483,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return type;
}
function getQuickTypeOfExpression(node: Expression) {
function getQuickTypeOfExpression(node: Expression): Type | undefined {
let expr = skipParentheses(node, /*excludeJSDocTypeAssertions*/ true);
if (isJSDocTypeAssertion(expr)) {
const type = getJSDocTypeAssertionType(expr);
@@ -36491,14 +36492,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
expr = skipParentheses(node);
if (isAwaitExpression(expr)) {
const type = getQuickTypeOfExpression(expr.expression);
return type ? getAwaitedType(type) : undefined;
}
// Optimize for the common case of a call to a function with a single non-generic call
// signature where we can just fetch the return type without checking the arguments.
if (isCallExpression(expr) && expr.expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(expr, /*checkArgumentIsStringLiteralLike*/ true) && !isSymbolOrSymbolForCall(expr)) {
const type = isCallChain(expr) ? getReturnTypeOfSingleNonGenericSignatureOfCallChain(expr) :
return isCallChain(expr) ? getReturnTypeOfSingleNonGenericSignatureOfCallChain(expr) :
getReturnTypeOfSingleNonGenericCallSignature(checkNonNullExpression(expr.expression));
if (type) {
return type;
}
}
else if (isAssertionExpression(expr) && !isConstTypeReference(expr.type)) {
return getTypeFromTypeNode((expr as TypeAssertion).type);