@@ -16877,18 +16877,22 @@ namespace ts {
16877
16877
}
16878
16878
}
16879
16879
16880
- function isCallWithEffects (node: CallExpression) {
16880
+ function getEffectsSignature (node: CallExpression) {
16881
16881
const links = getNodeLinks(node);
16882
- if (links.isCallWithEffects === undefined) {
16882
+ let signature = links.effectsSignature;
16883
+ if (signature === undefined) {
16883
16884
// A call expression parented by an expression statement is a potential assertion. Other call
16884
16885
// expressions are potential type predicate function calls.
16885
16886
const funcType = node.parent.kind === SyntaxKind.ExpressionStatement ? getTypeOfDottedName(node.expression) :
16886
16887
node.expression.kind !== SyntaxKind.SuperKeyword ? checkNonNullExpression(node.expression) :
16887
16888
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;
16890
16894
}
16891
- return links.isCallWithEffects ;
16895
+ return signature === unknownSignature ? undefined : signature ;
16892
16896
}
16893
16897
16894
16898
function hasTypePredicateOrNeverReturnType(signature: Signature) {
@@ -17110,8 +17114,8 @@ namespace ts {
17110
17114
}
17111
17115
17112
17116
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) {
17115
17119
const predicate = getTypePredicateOfSignature(signature);
17116
17120
if (predicate && predicate.kind === TypePredicateKind.Assertion) {
17117
17121
const flowType = getTypeAtFlowNode(flow.antecedent);
@@ -17712,9 +17716,9 @@ namespace ts {
17712
17716
}
17713
17717
17714
17718
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);
17718
17722
if (predicate && predicate.kind !== TypePredicateKind.Assertion) {
17719
17723
return narrowTypeByTypePredicate(type, predicate, callExpression, assumeTrue);
17720
17724
}
@@ -23695,7 +23699,8 @@ namespace ts {
23695
23699
}
23696
23700
23697
23701
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);
23699
23704
}
23700
23705
23701
23706
function functionHasImplicitReturn(func: FunctionLikeDeclaration) {
0 commit comments