Skip to content

Commit 75404a7

Browse files
committed
Addressing CR feedback
1 parent 0410394 commit 75404a7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4469,14 +4469,16 @@ module ts {
44694469
Debug.fail("should not get here");
44704470
}
44714471

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 {
44744475
if (type.flags & TypeFlags.Union) {
44754476
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;
44804482
}
44814483
}
44824484
}
@@ -4687,7 +4689,8 @@ module ts {
46874689
if (isTypeSubtypeOf(typeInfo.type, type)) {
46884690
return typeInfo.type;
46894691
}
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.
46914694
return removeTypesFromUnionType(type, typeInfo.flags, false);
46924695
}
46934696
else {
@@ -4757,7 +4760,8 @@ module ts {
47574760
return type;
47584761
}
47594762

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.
47614765
function narrowType(type: Type, expr: Expression, assumeTrue: boolean): Type {
47624766
switch (expr.kind) {
47634767
case SyntaxKind.ParenthesizedExpression:

0 commit comments

Comments
 (0)