@@ -4420,8 +4420,8 @@ namespace ts {
4420
4420
context.inferTypeParameters = (<ConditionalType>type).root.inferTypeParameters;
4421
4421
const extendsTypeNode = typeToTypeNodeHelper((<ConditionalType>type).extendsType, context);
4422
4422
context.inferTypeParameters = saveInferTypeParameters;
4423
- const trueTypeNode = typeToTypeNodeHelper (getTrueTypeFromConditionalType(<ConditionalType>type), context );
4424
- const falseTypeNode = typeToTypeNodeHelper (getFalseTypeFromConditionalType(<ConditionalType>type), context );
4423
+ const trueTypeNode = typeToTypeNodeOrCircularityElision (getTrueTypeFromConditionalType(<ConditionalType>type));
4424
+ const falseTypeNode = typeToTypeNodeOrCircularityElision (getFalseTypeFromConditionalType(<ConditionalType>type));
4425
4425
context.approximateLength += 15;
4426
4426
return createConditionalTypeNode(checkTypeNode, extendsTypeNode, trueTypeNode, falseTypeNode);
4427
4427
}
@@ -4431,6 +4431,21 @@ namespace ts {
4431
4431
4432
4432
return Debug.fail("Should be unreachable.");
4433
4433
4434
+
4435
+ function typeToTypeNodeOrCircularityElision(type: Type) {
4436
+ if (type.flags & TypeFlags.Union) {
4437
+ if (context.visitedTypes && context.visitedTypes.has("" + getTypeId(type))) {
4438
+ if (!(context.flags & NodeBuilderFlags.AllowAnonymousIdentifier)) {
4439
+ context.encounteredError = true;
4440
+ context.tracker?.reportCyclicStructureError?.();
4441
+ }
4442
+ return createElidedInformationPlaceholder(context);
4443
+ }
4444
+ return visitAndTransformType(type, type => typeToTypeNodeHelper(type, context));
4445
+ }
4446
+ return typeToTypeNodeHelper(type, context);
4447
+ }
4448
+
4434
4449
function createMappedTypeNodeFromType(type: MappedType) {
4435
4450
Debug.assert(!!(type.flags & TypeFlags.Object));
4436
4451
const readonlyToken = type.declaration.readonlyToken ? <ReadonlyToken | PlusToken | MinusToken>createToken(type.declaration.readonlyToken.kind) : undefined;
@@ -12978,10 +12993,12 @@ namespace ts {
12978
12993
return links.resolvedType;
12979
12994
}
12980
12995
12981
- function createIndexedAccessType(objectType: Type, indexType: Type) {
12996
+ function createIndexedAccessType(objectType: Type, indexType: Type, aliasSymbol: Symbol | undefined, aliasTypeArguments: readonly Type[] | undefined ) {
12982
12997
const type = <IndexedAccessType>createType(TypeFlags.IndexedAccess);
12983
12998
type.objectType = objectType;
12984
12999
type.indexType = indexType;
13000
+ type.aliasSymbol = aliasSymbol;
13001
+ type.aliasTypeArguments = aliasTypeArguments;
12985
13002
return type;
12986
13003
}
12987
13004
@@ -13316,11 +13333,11 @@ namespace ts {
13316
13333
return instantiateType(getTemplateTypeFromMappedType(objectType), templateMapper);
13317
13334
}
13318
13335
13319
- function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression): Type {
13320
- return getIndexedAccessTypeOrUndefined(objectType, indexType, accessNode, AccessFlags.None) || (accessNode ? errorType : unknownType);
13336
+ function getIndexedAccessType(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[] ): Type {
13337
+ return getIndexedAccessTypeOrUndefined(objectType, indexType, accessNode, AccessFlags.None, aliasSymbol, aliasTypeArguments ) || (accessNode ? errorType : unknownType);
13321
13338
}
13322
13339
13323
- function getIndexedAccessTypeOrUndefined(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, accessFlags = AccessFlags.None): Type | undefined {
13340
+ function getIndexedAccessTypeOrUndefined(objectType: Type, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression, accessFlags = AccessFlags.None, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[] ): Type | undefined {
13324
13341
if (objectType === wildcardType || indexType === wildcardType) {
13325
13342
return wildcardType;
13326
13343
}
@@ -13342,7 +13359,7 @@ namespace ts {
13342
13359
const id = objectType.id + "," + indexType.id;
13343
13360
let type = indexedAccessTypes.get(id);
13344
13361
if (!type) {
13345
- indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType));
13362
+ indexedAccessTypes.set(id, type = createIndexedAccessType(objectType, indexType, aliasSymbol, aliasTypeArguments ));
13346
13363
}
13347
13364
return type;
13348
13365
}
@@ -13370,7 +13387,7 @@ namespace ts {
13370
13387
if (wasMissingProp) {
13371
13388
return undefined;
13372
13389
}
13373
- return accessFlags & AccessFlags.Writing ? getIntersectionType(propTypes) : getUnionType(propTypes);
13390
+ return accessFlags & AccessFlags.Writing ? getIntersectionType(propTypes, aliasSymbol, aliasTypeArguments ) : getUnionType(propTypes, UnionReduction.Literal, aliasSymbol, aliasTypeArguments );
13374
13391
}
13375
13392
return getPropertyTypeForIndexType(objectType, apparentObjectType, indexType, indexType, /* supressNoImplicitAnyError */ false, accessNode, accessFlags | AccessFlags.CacheSymbol);
13376
13393
}
@@ -13380,7 +13397,8 @@ namespace ts {
13380
13397
if (!links.resolvedType) {
13381
13398
const objectType = getTypeFromTypeNode(node.objectType);
13382
13399
const indexType = getTypeFromTypeNode(node.indexType);
13383
- const resolved = getIndexedAccessType(objectType, indexType, node);
13400
+ const potentialAlias = getAliasSymbolForTypeNode(node);
13401
+ const resolved = getIndexedAccessType(objectType, indexType, node, potentialAlias, getTypeArgumentsForAliasSymbol(potentialAlias));
13384
13402
links.resolvedType = resolved.flags & TypeFlags.IndexedAccess &&
13385
13403
(<IndexedAccessType>resolved).objectType === objectType &&
13386
13404
(<IndexedAccessType>resolved).indexType === indexType ?
@@ -14531,7 +14549,7 @@ namespace ts {
14531
14549
return getIndexType(instantiateType((<IndexType>type).type, mapper));
14532
14550
}
14533
14551
if (flags & TypeFlags.IndexedAccess) {
14534
- return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper));
14552
+ return getIndexedAccessType(instantiateType((<IndexedAccessType>type).objectType, mapper), instantiateType((<IndexedAccessType>type).indexType, mapper), /*accessNode*/ undefined, type.aliasSymbol, instantiateTypes(type.aliasTypeArguments, mapper) );
14535
14553
}
14536
14554
if (flags & TypeFlags.Conditional) {
14537
14555
return getConditionalTypeInstantiation(<ConditionalType>type, combineTypeMappers((<ConditionalType>type).mapper, mapper));
0 commit comments