@@ -12375,17 +12375,19 @@ namespace ts {
12375
12375
return checkNoTypeArguments(node, symbol) ? type : errorType;
12376
12376
}
12377
12377
12378
- function getTypeAliasInstantiation(symbol: Symbol, typeArguments: readonly Type[] | undefined): Type {
12378
+ function getTypeAliasInstantiation(symbol: Symbol, typeArguments: readonly Type[] | undefined, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[] ): Type {
12379
12379
const type = getDeclaredTypeOfSymbol(symbol);
12380
12380
if (type === intrinsicMarkerType && intrinsicTypeKinds.has(symbol.escapedName as string) && typeArguments && typeArguments.length === 1) {
12381
12381
return getStringMappingType(symbol, typeArguments[0]);
12382
12382
}
12383
12383
const links = getSymbolLinks(symbol);
12384
12384
const typeParameters = links.typeParameters!;
12385
- const id = getTypeListId(typeArguments);
12385
+ const id = getTypeListId(typeArguments) + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "") ;
12386
12386
let instantiation = links.instantiations!.get(id);
12387
12387
if (!instantiation) {
12388
- links.instantiations!.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), isInJSFile(symbol.valueDeclaration)))));
12388
+ links.instantiations!.set(id, instantiation = instantiateType(type,
12389
+ createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), isInJSFile(symbol.valueDeclaration))),
12390
+ aliasSymbol, aliasTypeArguments));
12389
12391
}
12390
12392
return instantiation;
12391
12393
}
@@ -12411,7 +12413,8 @@ namespace ts {
12411
12413
typeParameters.length);
12412
12414
return errorType;
12413
12415
}
12414
- return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node));
12416
+ const aliasSymbol = getAliasSymbolForTypeNode(node);
12417
+ return getTypeAliasInstantiation(symbol, typeArgumentsFromTypeReferenceNode(node), aliasSymbol, getTypeArgumentsForAliasSymbol(aliasSymbol));
12415
12418
}
12416
12419
return checkNoTypeArguments(node, symbol) ? type : errorType;
12417
12420
}
@@ -15591,9 +15594,9 @@ namespace ts {
15591
15594
return getConditionalType(root, mapper);
15592
15595
}
15593
15596
15594
- function instantiateType(type: Type, mapper: TypeMapper | undefined): Type;
15595
- function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined): Type | undefined;
15596
- function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined): Type | undefined {
15597
+ function instantiateType(type: Type, mapper: TypeMapper | undefined, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[] ): Type;
15598
+ function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[] ): Type | undefined;
15599
+ function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[] ): Type | undefined {
15597
15600
if (!(type && mapper && couldContainTypeVariables(type))) {
15598
15601
return type;
15599
15602
}
@@ -15608,12 +15611,12 @@ namespace ts {
15608
15611
totalInstantiationCount++;
15609
15612
instantiationCount++;
15610
15613
instantiationDepth++;
15611
- const result = instantiateTypeWorker(type, mapper);
15614
+ const result = instantiateTypeWorker(type, mapper, aliasSymbol, aliasTypeArguments );
15612
15615
instantiationDepth--;
15613
15616
return result;
15614
15617
}
15615
15618
15616
- function instantiateTypeWorker(type: Type, mapper: TypeMapper): Type {
15619
+ function instantiateTypeWorker(type: Type, mapper: TypeMapper, aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined ): Type {
15617
15620
const flags = type.flags;
15618
15621
if (flags & TypeFlags.TypeParameter) {
15619
15622
return getMappedType(type, mapper);
@@ -15634,10 +15637,14 @@ namespace ts {
15634
15637
const origin = type.flags & TypeFlags.Union ? (<UnionType>type).origin : undefined;
15635
15638
const types = origin && origin.flags & TypeFlags.UnionOrIntersection ? (<UnionOrIntersectionType>origin).types : (<UnionOrIntersectionType>type).types;
15636
15639
const newTypes = instantiateTypes(types, mapper);
15637
- return newTypes === types ? type :
15638
- flags & TypeFlags.Intersection || origin && origin.flags & TypeFlags.Intersection ?
15639
- getIntersectionType(newTypes, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper)) :
15640
- getUnionType(newTypes, UnionReduction.Literal, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
15640
+ if (newTypes === types && aliasSymbol === type.aliasSymbol) {
15641
+ return type;
15642
+ }
15643
+ const newAliasSymbol = aliasSymbol || type.aliasSymbol;
15644
+ const newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
15645
+ return flags & TypeFlags.Intersection || origin && origin.flags & TypeFlags.Intersection ?
15646
+ getIntersectionType(newTypes, newAliasSymbol, newAliasTypeArguments) :
15647
+ getUnionType(newTypes, UnionReduction.Literal, newAliasSymbol, newAliasTypeArguments);
15641
15648
}
15642
15649
if (flags & TypeFlags.Index) {
15643
15650
return getIndexType(instantiateType((<IndexType>type).type, mapper));
@@ -15649,7 +15656,9 @@ namespace ts {
15649
15656
return getStringMappingType((<StringMappingType>type).symbol, instantiateType((<StringMappingType>type).type, mapper));
15650
15657
}
15651
15658
if (flags & TypeFlags.IndexedAccess) {
15652
- return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper), (<IndexedAccessType>type).noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper));
15659
+ const newAliasSymbol = aliasSymbol || type.aliasSymbol;
15660
+ const newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
15661
+ return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper), (<IndexedAccessType>type).noUncheckedIndexedAccessCandidate, /*accessNode*/ undefined, newAliasSymbol, newAliasTypeArguments);
15653
15662
}
15654
15663
if (flags & TypeFlags.Conditional) {
15655
15664
return getConditionalTypeInstantiation(<ConditionalType>type, combineTypeMappers((<ConditionalType>type).mapper, mapper));
0 commit comments