From 6d2c0037fcf4b88c66e8d0f40be3b25c180b7fd3 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 30 Nov 2018 16:42:14 -0800 Subject: [PATCH] Only count singleton unit types. --- src/compiler/checker.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8f1faaa368b..da22fecfb8d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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; }