Skip to content

Commit 5c8c82d

Browse files
committed
Narrow union types without remaining choices to void
1 parent d288ece commit 5c8c82d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/compiler/checker.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -4200,8 +4200,13 @@ module ts {
42004200
if(type.flags & TypeFlags.Union) {
42014201
var types = (<UnionType>type).types;
42024202
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;
42034207
}
4204-
return type;
4208+
4209+
return voidType;
42054210
}
42064211

42074212
// Check if a given variable is assigned within a given syntax node
@@ -4278,7 +4283,7 @@ module ts {
42784283
}
42794284
return false;
42804285
}
4281-
}
4286+
}
42824287

42834288
// Get the narrowed type of a given symbol at a given location
42844289
function getNarrowedTypeOfSymbol(symbol: Symbol, node: Node) {

0 commit comments

Comments
 (0)