From ba5ba4187698b36d2e6f96bc23a0be9d3005594f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 30 Nov 2018 15:09:02 -0800 Subject: [PATCH] Types are only overlappy if their index types are single 'keyof's or literal types. --- src/compiler/checker.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) 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;