Merge pull request #10839 from Microsoft/fixNarrowingWithTypeParameter

Fix narrowing with constrained type parameter
This commit is contained in:
Mohamed Hegazy
2016-09-12 11:25:21 -07:00
committed by GitHub
5 changed files with 145 additions and 1 deletions

View File

@@ -8729,7 +8729,7 @@ namespace ts {
// type. Otherwise, the types are completely unrelated, so narrow to an intersection of the
// two types.
const targetType = type.flags & TypeFlags.TypeParameter ? getApparentType(type) : type;
return isTypeSubtypeOf(candidate, targetType) ? candidate :
return isTypeSubtypeOf(candidate, type) ? candidate :
isTypeAssignableTo(type, candidate) ? type :
isTypeAssignableTo(candidate, targetType) ? candidate :
getIntersectionType([type, candidate]);