@@ -8981,6 +8981,28 @@ namespace ts {
89818981 return isLengthPushOrUnshift || isElementAssignment;
89828982 }
89838983
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+
89849006 function getFlowTypeOfReference(reference: Node, declaredType: Type, assumeInitialized: boolean, flowContainer: Node) {
89859007 let key: string;
89869008 if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) {
@@ -9495,7 +9517,7 @@ namespace ts {
94959517 }
94969518
94979519 function narrowTypeByTypePredicate(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
9498- if (!hasMatchingArgument(callExpression, reference)) {
9520+ if (!hasMatchingArgument(callExpression, reference) || !maybeTypePredicateCall(callExpression) ) {
94999521 return type;
95009522 }
95019523 const signature = getResolvedSignature(callExpression);
0 commit comments