@@ -8981,6 +8981,28 @@ namespace ts {
8981
8981
return isLengthPushOrUnshift || isElementAssignment;
8982
8982
}
8983
8983
8984
+ function maybeTypePredicateCall(node: CallExpression) {
8985
+ const links = getNodeLinks(node);
8986
+ if (links.maybeTypePredicate === undefined) {
8987
+ links.maybeTypePredicate = getMaybeTypePredicate(node);
8988
+ }
8989
+ return links.maybeTypePredicate;
8990
+ }
8991
+
8992
+ function getMaybeTypePredicate(node: CallExpression) {
8993
+ if (node.expression.kind !== SyntaxKind.SuperKeyword) {
8994
+ const funcType = checkNonNullExpression(node.expression);
8995
+ if (funcType !== silentNeverType) {
8996
+ const apparentType = getApparentType(funcType);
8997
+ if (apparentType !== unknownType) {
8998
+ const callSignatures = getSignaturesOfType(apparentType, SignatureKind.Call);
8999
+ return !!forEach(callSignatures, sig => sig.typePredicate);
9000
+ }
9001
+ }
9002
+ }
9003
+ return false;
9004
+ }
9005
+
8984
9006
function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean, flowContainer: Node) {
8985
9007
let key: string;
8986
9008
if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
@@ -9495,7 +9517,7 @@ namespace ts {
9495
9517
}
9496
9518
9497
9519
function narrowTypeByTypePredicate(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
9498
- if (!hasMatchingArgument(callExpression, reference)) {
9520
+ if (!hasMatchingArgument(callExpression, reference) || !maybeTypePredicateCall(callExpression) ) {
9499
9521
return type;
9500
9522
}
9501
9523
const signature = getResolvedSignature(callExpression);
0 commit comments