Fix #6277 - stop looking for any specifically, and use isTypeSubtypeOf like the old code

This commit is contained in:
Wesley Wigham
2016-01-03 07:43:30 -05:00
parent 6be0206242
commit 7bb2ee56d0
5 changed files with 192 additions and 4 deletions

View File

@@ -6674,10 +6674,6 @@ namespace ts {
if (typeInfo && typeInfo.type === undefinedType) {
return type;
}
// If the type to be narrowed is any and we're checking a primitive with assumeTrue=true, return the primitive
if (!!(type.flags & TypeFlags.Any) && typeInfo && assumeTrue) {
return typeInfo.type;
}
let flags: TypeFlags;
if (typeInfo) {
flags = typeInfo.flags;
@@ -6688,6 +6684,10 @@ namespace ts {
}
// At this point we can bail if it's not a union
if (!(type.flags & TypeFlags.Union)) {
// If we're on the true branch and the type is a subtype, we should return the primitive type
if (assumeTrue && typeInfo && isTypeSubtypeOf(typeInfo.type, type)) {
return typeInfo.type;
}
// If the active non-union type would be removed from a union by this type guard, return an empty union
return filterUnion(type) ? type : emptyUnionType;
}