Only count singleton unit types.

This commit is contained in:
Daniel Rosenwasser 2018-11-30 16:42:14 -08:00
parent d35cfc13cf
commit 6d2c0037fc

View File

@ -11976,22 +11976,20 @@ namespace ts {
bestMatch = target;
matchingCount = Infinity;
}
else if (isLiteralType(overlap)) {
else if (overlap.flags & TypeFlags.Union) {
// We only want to account for literal types otherwise.
// If we have a union of index types, it seems likely that we
// needed to elaborate between two generic mapped types anyway.
if (overlap.flags & TypeFlags.Union) {
const len = length(filter((overlap as UnionType).types, isUnitType));
if (len >= matchingCount) {
bestMatch = target;
matchingCount = len;
}
}
else if (1 >= matchingCount) {
const len = length(filter((overlap as UnionType).types, isUnitType));
if (len >= matchingCount) {
bestMatch = target;
matchingCount = 1;
matchingCount = len;
}
}
else if (isUnitType(overlap) && 1 >= matchingCount) {
bestMatch = target;
matchingCount = 1;
}
}
return bestMatch;
}