Skip to content

Commit

Permalink
Narrow union types without remaining choices to void. This time takin…
Browse files Browse the repository at this point in the history
…g into account union types and single types sources.
  • Loading branch information
Nevor committed Nov 3, 2014
1 parent 5c8c82d commit d82f8f5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/compiler/checker.ts
Expand Up @@ -4199,13 +4199,13 @@ module ts {
function keepAssignableTypes(type : Type, targetType : Type, assumeAssignable: boolean): Type {
if(type.flags & TypeFlags.Union) {
var types = (<UnionType>type).types;
return getUnionType(filter(types, t => assumeAssignable ? isTypeAssignableTo(t, targetType) : !isTypeAssignableTo(t, targetType)));
} else if(isTypeAssignableTo(type, targetType) && assumeAssignable) {
return type;
} else if(!isTypeAssignableTo(type, targetType) && !assumeAssignable) {
return type;
} else {
var types = [type];
}
var remainingTypes = filter(types, t => assumeAssignable ? isTypeAssignableTo(t, targetType) : !isTypeAssignableTo(t, targetType));
if(remainingTypes.length > 0) {
return getUnionType(remainingTypes);
}

return voidType;
}

Expand Down

0 comments on commit d82f8f5

Please sign in to comment.