From a9251723c7b8491407f48977245211478a67b726 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 8 Feb 2018 17:10:25 -0800 Subject: [PATCH] Properly detect identical conditional types in caching logic --- src/compiler/checker.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6211c9153bf..2341b983ceb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8219,16 +8219,17 @@ namespace ts { const erasedCheckType = getActualTypeParameter(checkType); const trueType = instantiateType(baseTrueType, mapper); const falseType = instantiateType(baseFalseType, mapper); - const id = target && (target.id + "," + erasedCheckType.id + "," + extendsType.id + "," + trueType.id + "," + falseType.id); - const cached = id && conditionalTypes.get(id); + // We compute the cache key from the ids of the four constituent types, plus an indicator of whether the + // type is distributive (i.e. whether the original declaration has a type parameter as the check type). + const isDistributive = (target ? target.checkType : erasedCheckType).flags & TypeFlags.TypeParameter ? 1 : 0; + const id = erasedCheckType.id + "," + extendsType.id + "," + trueType.id + "," + falseType.id + "," + isDistributive; + const cached = conditionalTypes.get(id); if (cached) { return cached; } const result = createConditionalType(erasedCheckType, extendsType, trueType, falseType, inferTypeParameters, target, mapper, aliasSymbol, instantiateTypes(baseAliasTypeArguments, mapper)); - if (id) { - conditionalTypes.set(id, result); - } + conditionalTypes.set(id, result); return result; }