@@ -16877,18 +16877,22 @@ namespace ts {
1687716877 }
1687816878 }
1687916879
16880- function isCallWithEffects (node: CallExpression) {
16880+ function getEffectsSignature (node: CallExpression) {
1688116881 const links = getNodeLinks(node);
16882- if (links.isCallWithEffects === undefined) {
16882+ let signature = links.effectsSignature;
16883+ if (signature === undefined) {
1688316884 // A call expression parented by an expression statement is a potential assertion. Other call
1688416885 // expressions are potential type predicate function calls.
1688516886 const funcType = node.parent.kind === SyntaxKind.ExpressionStatement ? getTypeOfDottedName(node.expression) :
1688616887 node.expression.kind !== SyntaxKind.SuperKeyword ? checkNonNullExpression(node.expression) :
1688716888 undefined;
16888- const apparentType = funcType && getApparentType(funcType) || unknownType;
16889- links.isCallWithEffects = some(getSignaturesOfType(apparentType, SignatureKind.Call), hasTypePredicateOrNeverReturnType);
16889+ const signatures = getSignaturesOfType(funcType && getApparentType(funcType) || unknownType, SignatureKind.Call);
16890+ const candidate = signatures.length === 1 && !signatures[0].typeParameters ? signatures[0] :
16891+ some(signatures, hasTypePredicateOrNeverReturnType) ? getResolvedSignature(node) :
16892+ undefined;
16893+ signature = links.effectsSignature = candidate && hasTypePredicateOrNeverReturnType(candidate) ? candidate : unknownSignature;
1689016894 }
16891- return links.isCallWithEffects ;
16895+ return signature === unknownSignature ? undefined : signature ;
1689216896 }
1689316897
1689416898 function hasTypePredicateOrNeverReturnType(signature: Signature) {
@@ -17110,8 +17114,8 @@ namespace ts {
1711017114 }
1711117115
1711217116 function getTypeAtFlowCall(flow: FlowCall): FlowType | undefined {
17113- if (isCallWithEffects( flow.node)) {
17114- const signature = getResolvedSignature(flow.node);
17117+ const signature = getEffectsSignature( flow.node);
17118+ if (signature) {
1711517119 const predicate = getTypePredicateOfSignature(signature);
1711617120 if (predicate && predicate.kind === TypePredicateKind.Assertion) {
1711717121 const flowType = getTypeAtFlowNode(flow.antecedent);
@@ -17712,9 +17716,9 @@ namespace ts {
1771217716 }
1771317717
1771417718 function narrowTypeByCallExpression(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
17715- if (hasMatchingArgument(callExpression, reference) && isCallWithEffects(callExpression) ) {
17716- const signature = getResolvedSignature (callExpression);
17717- const predicate = getTypePredicateOfSignature(signature);
17719+ if (hasMatchingArgument(callExpression, reference)) {
17720+ const signature = getEffectsSignature (callExpression);
17721+ const predicate = signature && getTypePredicateOfSignature(signature);
1771817722 if (predicate && predicate.kind !== TypePredicateKind.Assertion) {
1771917723 return narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue);
1772017724 }
@@ -23695,7 +23699,8 @@ namespace ts {
2369523699 }
2369623700
2369723701 function isNeverFunctionCall(expr: Expression) {
23698- return expr.kind === SyntaxKind.CallExpression && isCallWithEffects(<CallExpression>expr) && !!(getTypeOfExpression(expr).flags & TypeFlags.Never);
23702+ const signature = expr.kind === SyntaxKind.CallExpression && getEffectsSignature(<CallExpression>expr);
23703+ return !!(signature && getReturnTypeOfSignature(signature).flags & TypeFlags.Never);
2369923704 }
2370023705
2370123706 function functionHasImplicitReturn(func: FunctionLikeDeclaration) {
0 commit comments