@@ -22999,11 +22999,16 @@ namespace ts {
22999
22999
}
23000
23000
}
23001
23001
23002
- // If the candidate type is a subtype of the target type, narrow to the candidate type,
23003
- // if the target type is a subtype of the candidate type, narrow to the target type,
23004
- // otherwise, narrow to an intersection of the two types.
23005
- return isTypeSubtypeOf(candidate, type) ? candidate : isTypeSubtypeOf(type, candidate) ? type : getIntersectionType([type, candidate]);
23006
- }
23002
+ // If the candidate type is a subtype of the target type, narrow to the candidate type.
23003
+ // Otherwise, if the target type is assignable to the candidate type, keep the target type.
23004
+ // Otherwise, if the candidate type is assignable to the target type, narrow to the candidate
23005
+ // type. Otherwise, the types are completely unrelated, so narrow to an intersection of the
23006
+ // two types.
23007
+ return isTypeSubtypeOf(candidate, type) ? candidate :
23008
+ isTypeAssignableTo(type, candidate) ? type :
23009
+ isTypeAssignableTo(candidate, type) ? candidate :
23010
+ getIntersectionType([type, candidate]);
23011
+ }
23007
23012
23008
23013
function narrowTypeByCallExpression(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
23009
23014
if (hasMatchingArgument(callExpression, reference)) {
0 commit comments