diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b0c22b61341..394f13bc2cc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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;