Skip to content

Commit d82f8f5

Browse files
committed
Narrow union types without remaining choices to void. This time taking into account union types and single types sources.
1 parent 5c8c82d commit d82f8f5

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/compiler/checker.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4199,13 +4199,13 @@ module ts {
41994199
function keepAssignableTypes(type : Type, targetType : Type, assumeAssignable: boolean): Type {
42004200
if(type.flags & TypeFlags.Union) {
42014201
var types = (<UnionType>type).types;
4202-
return getUnionType(filter(types, t => assumeAssignable ? isTypeAssignableTo(t, targetType) : !isTypeAssignableTo(t, targetType)));
4203-
} else if(isTypeAssignableTo(type, targetType) && assumeAssignable) {
4204-
return type;
4205-
} else if(!isTypeAssignableTo(type, targetType) && !assumeAssignable) {
4206-
return type;
4202+
} else {
4203+
var types = [type];
4204+
}
4205+
var remainingTypes = filter(types, t => assumeAssignable ? isTypeAssignableTo(t, targetType) : !isTypeAssignableTo(t, targetType));
4206+
if(remainingTypes.length > 0) {
4207+
return getUnionType(remainingTypes);
42074208
}
4208-
42094209
return voidType;
42104210
}
42114211

0 commit comments

Comments
 (0)