Skip to content

Commit a925172

Browse files
committed
Properly detect identical conditional types in caching logic
1 parent 4150a46 commit a925172

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/compiler/checker.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8219,16 +8219,17 @@ namespace ts {
82198219
const erasedCheckType = getActualTypeParameter(checkType);
82208220
const trueType = instantiateType(baseTrueType, mapper);
82218221
const falseType = instantiateType(baseFalseType, mapper);
8222-
const id = target && (target.id + "," + erasedCheckType.id + "," + extendsType.id + "," + trueType.id + "," + falseType.id);
8223-
const cached = id && conditionalTypes.get(id);
8222+
// We compute the cache key from the ids of the four constituent types, plus an indicator of whether the
8223+
// type is distributive (i.e. whether the original declaration has a type parameter as the check type).
8224+
const isDistributive = (target ? target.checkType : erasedCheckType).flags & TypeFlags.TypeParameter ? 1 : 0;
8225+
const id = erasedCheckType.id + "," + extendsType.id + "," + trueType.id + "," + falseType.id + "," + isDistributive;
8226+
const cached = conditionalTypes.get(id);
82248227
if (cached) {
82258228
return cached;
82268229
}
82278230
const result = createConditionalType(erasedCheckType, extendsType, trueType, falseType,
82288231
inferTypeParameters, target, mapper, aliasSymbol, instantiateTypes(baseAliasTypeArguments, mapper));
8229-
if (id) {
8230-
conditionalTypes.set(id, result);
8231-
}
8232+
conditionalTypes.set(id, result);
82328233
return result;
82338234
}
82348235

0 commit comments

Comments
 (0)