Types are only overlappy if their index types are single 'keyof's or literal types.

This commit is contained in:
Daniel Rosenwasser
2018-11-30 15:09:02 -08:00
parent 448baaeb2f
commit ba5ba41876

View File

@@ -11976,19 +11976,21 @@ namespace ts {
bestMatch = target;
matchingCount = Infinity;
}
else if (overlap.flags & TypeFlags.Union) {
// Some subset overlap if we have only string literals.
else if (isLiteralType(overlap)) {
// 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.
const len = length((overlap as UnionType).types);
if (len >= matchingCount) {
bestMatch = target;
matchingCount = len;
if (overlap.flags & TypeFlags.Union) {
const len = length((overlap as UnionType).types);
if (len >= matchingCount) {
bestMatch = target;
matchingCount = len;
}
}
else if (1 >= matchingCount) {
bestMatch = target;
matchingCount = 1;
}
}
else if (!(overlap.flags & TypeFlags.Never) && 1 >= matchingCount) {
bestMatch = target;
matchingCount = 1;
}
}
return bestMatch;