Skip to content

Commit efd7bc9

Browse files
committed
Include alias type arguments in keys for aliased types
1 parent 8324dec commit efd7bc9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12325,6 +12325,10 @@ namespace ts {
1232512325
return result;
1232612326
}
1232712327

12328+
function getAliasId(aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined) {
12329+
return aliasSymbol ? `@${getSymbolId(aliasSymbol)}` + (aliasTypeArguments ? `:${getTypeListId(aliasTypeArguments)}` : "") : "";
12330+
}
12331+
1232812332
// This function is used to propagate certain flags when creating new object type references and union types.
1232912333
// It is only necessary to do so if a constituent type might be the undefined type, the null type, the type
1233012334
// of an object literal or the anyFunctionType. This is because there are operations in the type checker
@@ -12453,7 +12457,7 @@ namespace ts {
1245312457
}
1245412458
const links = getSymbolLinks(symbol);
1245512459
const typeParameters = links.typeParameters!;
12456-
const id = getTypeListId(typeArguments) + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
12460+
const id = getTypeListId(typeArguments) + getAliasId(aliasSymbol, aliasTypeArguments);
1245712461
let instantiation = links.instantiations!.get(id);
1245812462
if (!instantiation) {
1245912463
links.instantiations!.set(id, instantiation = instantiateTypeWithAlias(type,
@@ -13487,7 +13491,7 @@ namespace ts {
1348713491
origin.flags & TypeFlags.Union ? `|${getTypeListId((<UnionType>origin).types)}` :
1348813492
origin.flags & TypeFlags.Intersection ? `&${getTypeListId((<IntersectionType>origin).types)}` :
1348913493
`#${(<IndexType>origin).type.id}`;
13490-
const id = typeKey + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
13494+
const id = typeKey + getAliasId(aliasSymbol, aliasTypeArguments);
1349113495
let type = unionTypes.get(id);
1349213496
if (!type) {
1349313497
type = createUnionType(types, aliasSymbol, aliasTypeArguments, origin);
@@ -13724,7 +13728,7 @@ namespace ts {
1372413728
if (typeSet.length === 1) {
1372513729
return typeSet[0];
1372613730
}
13727-
const id = getTypeListId(typeSet) + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
13731+
const id = getTypeListId(typeSet) + getAliasId(aliasSymbol, aliasTypeArguments);
1372813732
let result = intersectionTypes.get(id);
1372913733
if (!result) {
1373013734
if (includes & TypeFlags.Union) {
@@ -14486,7 +14490,7 @@ namespace ts {
1448614490
return objectType;
1448714491
}
1448814492
// Defer the operation by creating an indexed access type.
14489-
const id = objectType.id + "," + indexType.id + (shouldIncludeUndefined ? "?" : "") + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
14493+
const id = objectType.id + "," + indexType.id + (shouldIncludeUndefined ? "?" : "") + getAliasId(aliasSymbol, aliasTypeArguments);
1449014494
let type = indexedAccessTypes.get(id);
1449114495
if (!type) {
1449214496
indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType, aliasSymbol, aliasTypeArguments, shouldIncludeUndefined));
@@ -15481,15 +15485,15 @@ namespace ts {
1548115485
const combinedMapper = combineTypeMappers(type.mapper, mapper);
1548215486
const typeArguments = map(typeParameters, t => getMappedType(t, combinedMapper));
1548315487
const newAliasSymbol = aliasSymbol || type.aliasSymbol;
15484-
const id = getTypeListId(typeArguments) + (newAliasSymbol ? `@${getSymbolId(newAliasSymbol)}` : "");
15488+
const newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
15489+
const id = getTypeListId(typeArguments) + getAliasId(newAliasSymbol, newAliasTypeArguments);
1548515490
if (!target.instantiations) {
1548615491
target.instantiations = new Map<string, Type>();
15487-
target.instantiations.set(getTypeListId(typeParameters) + (target.aliasSymbol ? `@${getSymbolId(target.aliasSymbol)}` : ""), target);
15492+
target.instantiations.set(getTypeListId(typeParameters) + getAliasId(target.aliasSymbol, target.aliasTypeArguments), target);
1548815493
}
1548915494
let result = target.instantiations.get(id);
1549015495
if (!result) {
1549115496
const newMapper = createTypeMapper(typeParameters, typeArguments);
15492-
const newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
1549315497
result = target.objectFlags & ObjectFlags.Reference ? createDeferredTypeReference((<DeferredTypeReference>type).target, (<DeferredTypeReference>type).node, newMapper, newAliasSymbol, newAliasTypeArguments) :
1549415498
target.objectFlags & ObjectFlags.Mapped ? instantiateMappedType(<MappedType>target, newMapper, newAliasSymbol, newAliasTypeArguments) :
1549515499
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
@@ -15657,7 +15661,7 @@ namespace ts {
1565715661
// mapper to the type parameters to produce the effective list of type arguments, and compute the
1565815662
// instantiation cache key from the type IDs of the type arguments.
1565915663
const typeArguments = map(root.outerTypeParameters, t => getMappedType(t, mapper));
15660-
const id = getTypeListId(typeArguments) + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
15664+
const id = getTypeListId(typeArguments) + getAliasId(aliasSymbol, aliasTypeArguments);
1566115665
let result = root.instantiations!.get(id);
1566215666
if (!result) {
1566315667
const newMapper = createTypeMapper(root.outerTypeParameters, typeArguments);

0 commit comments

Comments
 (0)