Revert assignability cases in getNarrowedType (#42231)

* Revert subtype narrowing changes from readonly array PRs

* Adds a test for the change

* More baselines
This commit is contained in:
Orta Therox
2021-02-09 23:03:11 +00:00
committed by GitHub
parent 1b19af0f14
commit 8c5fa5cc91
13 changed files with 453 additions and 35 deletions

View File

@@ -23094,10 +23094,15 @@ namespace ts {
}
}
// If the candidate type is a subtype of the target type, narrow to the candidate type,
// if the target type is a subtype of the candidate type, narrow to the target type,
// otherwise, narrow to an intersection of the two types.
return isTypeSubtypeOf(candidate, type) ? candidate : isTypeSubtypeOf(type, candidate) ? type : getIntersectionType([type, candidate]);
// If the candidate type is a subtype of the target type, narrow to the candidate type.
// Otherwise, if the target type is assignable to the candidate type, keep the target type.
// Otherwise, if the candidate type is assignable to the target type, narrow to the candidate
// type. Otherwise, the types are completely unrelated, so narrow to an intersection of the
// two types.
return isTypeSubtypeOf(candidate, type) ? candidate :
isTypeAssignableTo(type, candidate) ? type :
isTypeAssignableTo(candidate, type) ? candidate :
getIntersectionType([type, candidate]);
}
function narrowTypeByCallExpression(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {