Skip to content

Commit d615d21

Browse files
committed
Add cache of anonymous object type instantiations to TypeMapper
1 parent ca593ec commit d615d21

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4487,6 +4487,15 @@ namespace ts {
44874487
}
44884488

44894489
function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType {
4490+
if (mapper.instantiations) {
4491+
let cachedType = mapper.instantiations[type.id];
4492+
if (cachedType) {
4493+
return cachedType;
4494+
}
4495+
}
4496+
else {
4497+
mapper.instantiations = [];
4498+
}
44904499
// Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it
44914500
let result = <ResolvedType>createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol);
44924501
result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol);
@@ -4497,6 +4506,7 @@ namespace ts {
44974506
let numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
44984507
if (stringIndexType) result.stringIndexType = instantiateType(stringIndexType, mapper);
44994508
if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper);
4509+
mapper.instantiations[type.id] = result;
45004510
return result;
45014511
}
45024512

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,7 @@ namespace ts {
19531953
/* @internal */
19541954
export interface TypeMapper {
19551955
(t: TypeParameter): Type;
1956+
instantiations?: Type[]; // Cache of instantiations created using this type mapper.
19561957
context?: InferenceContext; // The inference context this mapper was created from.
19571958
// Only inference mappers have this set (in createInferenceMapper).
19581959
// The identity mapper and regular instantiation mappers do not need it.

0 commit comments

Comments
 (0)