Skip to content

Commit d2c0952

Browse files
committed
Revert type predicates to not have instanceof special casing
1 parent 2bcb6e9 commit d2c0952

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9721,20 +9721,20 @@ namespace ts {
97219721
}
97229722

97239723
if (targetType) {
9724-
return getNarrowedType(type, targetType, assumeTrue);
9724+
return getNarrowedType(type, targetType, assumeTrue, isTypeInstanceOf);
97259725
}
97269726

97279727
return type;
97289728
}
97299729

9730-
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean) {
9730+
function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean, isRelated: (source: Type, target: Type) => boolean) {
97319731
if (!assumeTrue) {
9732-
return filterType(type, t => !isTypeInstanceOf(t, candidate));
9732+
return filterType(type, t => !isRelated(t, candidate));
97339733
}
97349734
// If the current type is a union type, remove all constituents that couldn't be instances of
97359735
// the candidate type. If one or more constituents remain, return a union of those.
97369736
if (type.flags & TypeFlags.Union) {
9737-
const assignableType = filterType(type, t => isTypeInstanceOf(t, candidate));
9737+
const assignableType = filterType(type, t => isRelated(t, candidate));
97389738
if (!(assignableType.flags & TypeFlags.Never)) {
97399739
return assignableType;
97409740
}
@@ -9770,7 +9770,7 @@ namespace ts {
97709770
const predicateArgument = callExpression.arguments[predicate.parameterIndex];
97719771
if (predicateArgument) {
97729772
if (isMatchingReference(reference, predicateArgument)) {
9773-
return getNarrowedType(type, predicate.type, assumeTrue);
9773+
return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf);
97749774
}
97759775
if (containsMatchingReference(reference, predicateArgument)) {
97769776
return declaredType;
@@ -9783,7 +9783,7 @@ namespace ts {
97839783
const accessExpression = invokedExpression as ElementAccessExpression | PropertyAccessExpression;
97849784
const possibleReference = skipParentheses(accessExpression.expression);
97859785
if (isMatchingReference(reference, possibleReference)) {
9786-
return getNarrowedType(type, predicate.type, assumeTrue);
9786+
return getNarrowedType(type, predicate.type, assumeTrue, isTypeSubtypeOf);
97879787
}
97889788
if (containsMatchingReference(reference, possibleReference)) {
97899789
return declaredType;

0 commit comments

Comments
 (0)