@@ -4469,14 +4469,16 @@ module ts {
4469
4469
Debug.fail("should not get here");
4470
4470
}
4471
4471
4472
- // For a union type, remove all constituent types for which the given flags have the given state
4473
- function removeTypesFromUnionType(type: Type, maskFlags: TypeFlags, maskState: boolean): Type {
4472
+ // For a union type, remove all constituent types for that are of the given type kind (when isOfTypeKind is true)
4473
+ // or not of the given type kind (when isOfTypeKind is false)
4474
+ function removeTypesFromUnionType(type: Type, typeKind: TypeFlags, isOfTypeKind: boolean): Type {
4474
4475
if (type.flags & TypeFlags.Union) {
4475
4476
var types = (<UnionType>type).types;
4476
- if (forEach(types, t => !(t.flags & maskFlags) !== maskState)) {
4477
- var reducedType = getUnionType(filter(types, t => !(t.flags & maskFlags) === maskState));
4478
- if (reducedType !== emptyObjectType) {
4479
- return reducedType;
4477
+ if (forEach(types, t => !!(t.flags & typeKind) === isOfTypeKind)) {
4478
+ // Above we checked if we have anything to remove, now use the opposite test to do the removal
4479
+ var narrowedType = getUnionType(filter(types, t => !(t.flags & typeKind) === isOfTypeKind));
4480
+ if (narrowedType !== emptyObjectType) {
4481
+ return narrowedType;
4480
4482
}
4481
4483
}
4482
4484
}
@@ -4687,7 +4689,8 @@ module ts {
4687
4689
if (isTypeSubtypeOf(typeInfo.type, type)) {
4688
4690
return typeInfo.type;
4689
4691
}
4690
- // Otherwise, remove all types that aren't of the primitive type kind
4692
+ // Otherwise, remove all types that aren't of the primitive type kind. This can happen when the type is
4693
+ // union of enum types and other types.
4691
4694
return removeTypesFromUnionType(type, typeInfo.flags, false);
4692
4695
}
4693
4696
else {
@@ -4757,7 +4760,8 @@ module ts {
4757
4760
return type;
4758
4761
}
4759
4762
4760
- // Narrow the given type based on the given expression having the assumed boolean value
4763
+ // Narrow the given type based on the given expression having the assumed boolean value. The returned type
4764
+ // will be a subtype or the same type as the argument.
4761
4765
function narrowType(type: Type, expr: Expression, assumeTrue: boolean): Type {
4762
4766
switch (expr.kind) {
4763
4767
case SyntaxKind.ParenthesizedExpression:
0 commit comments