@@ -9721,20 +9721,20 @@ namespace ts {
9721
9721
}
9722
9722
9723
9723
if (targetType) {
9724
- return getNarrowedType(type, targetType, assumeTrue);
9724
+ return getNarrowedType(type, targetType, assumeTrue, isTypeInstanceOf );
9725
9725
}
9726
9726
9727
9727
return type;
9728
9728
}
9729
9729
9730
- function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean) {
9730
+ function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean, isRelated: (source: Type, target: Type) => boolean ) {
9731
9731
if (!assumeTrue) {
9732
- return filterType(type, t => !isTypeInstanceOf (t, candidate));
9732
+ return filterType(type, t => !isRelated (t, candidate));
9733
9733
}
9734
9734
// If the current type is a union type, remove all constituents that couldn't be instances of
9735
9735
// the candidate type. If one or more constituents remain, return a union of those.
9736
9736
if (type.flags & TypeFlags.Union) {
9737
- const assignableType = filterType(type, t => isTypeInstanceOf (t, candidate));
9737
+ const assignableType = filterType(type, t => isRelated (t, candidate));
9738
9738
if (!(assignableType.flags & TypeFlags.Never)) {
9739
9739
return assignableType;
9740
9740
}
@@ -9770,7 +9770,7 @@ namespace ts {
9770
9770
const predicateArgument = callExpression.arguments[predicate.parameterIndex];
9771
9771
if (predicateArgument) {
9772
9772
if (isMatchingReference(reference, predicateArgument)) {
9773
- return getNarrowedType(type, predicate.type, assumeTrue);
9773
+ return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf );
9774
9774
}
9775
9775
if (containsMatchingReference(reference, predicateArgument)) {
9776
9776
return declaredType;
@@ -9783,7 +9783,7 @@ namespace ts {
9783
9783
const accessExpression = invokedExpression as ElementAccessExpression | PropertyAccessExpression;
9784
9784
const possibleReference = skipParentheses(accessExpression.expression);
9785
9785
if (isMatchingReference(reference, possibleReference)) {
9786
- return getNarrowedType(type, predicate.type, assumeTrue);
9786
+ return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf );
9787
9787
}
9788
9788
if (containsMatchingReference(reference, possibleReference)) {
9789
9789
return declaredType;
0 commit comments