@@ -530,6 +530,7 @@ namespace ts {
530530 ResolvedBaseConstructorType,
531531 DeclaredType,
532532 ResolvedReturnType,
533+ ResolvedBaseConstraint,
533534 }
534535
535536 const enum CheckMode {
@@ -4254,7 +4255,7 @@ namespace ts {
42544255 return -1;
42554256 }
42564257
4257- function hasType(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): Type {
4258+ function hasType(target: TypeSystemEntity, propertyName: TypeSystemPropertyName): Type | boolean {
42584259 if (propertyName === TypeSystemPropertyName.Type) {
42594260 return getSymbolLinks(<Symbol>target).type;
42604261 }
@@ -4267,6 +4268,10 @@ namespace ts {
42674268 if (propertyName === TypeSystemPropertyName.ResolvedReturnType) {
42684269 return (<Signature>target).resolvedReturnType;
42694270 }
4271+ if (propertyName === TypeSystemPropertyName.ResolvedBaseConstraint) {
4272+ const bc = (<TypeParameter | UnionOrIntersectionType>target).resolvedBaseConstraint;
4273+ return bc && bc !== circularConstraintType;
4274+ }
42704275
42714276 Debug.fail("Unhandled TypeSystemPropertyName " + propertyName);
42724277 }
@@ -6301,9 +6306,9 @@ namespace ts {
63016306 (type.typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(type.declaration.typeParameter)));
63026307 }
63036308
6304- function getConstraintTypeFromMappedType(type: MappedType, typeStack?: Type[] ) {
6309+ function getConstraintTypeFromMappedType(type: MappedType) {
63056310 return type.constraintType ||
6306- (type.constraintType = instantiateType(getConstraintOfTypeParameter(getTypeParameterFromMappedType(type), typeStack ), type.mapper || identityMapper) || unknownType);
6311+ (type.constraintType = instantiateType(getConstraintOfTypeParameter(getTypeParameterFromMappedType(type)), type.mapper || identityMapper) || unknownType);
63076312 }
63086313
63096314 function getTemplateTypeFromMappedType(type: MappedType) {
@@ -6351,8 +6356,8 @@ namespace ts {
63516356 return getObjectFlags(type) & ObjectFlags.Mapped && !!(<MappedType>type).declaration.questionToken;
63526357 }
63536358
6354- function isGenericMappedType(type: Type, typeStack?: Type[] ): type is MappedType {
6355- return getObjectFlags(type) & ObjectFlags.Mapped && isGenericIndexType(getConstraintTypeFromMappedType(<MappedType>type, typeStack ));
6359+ function isGenericMappedType(type: Type): type is MappedType {
6360+ return getObjectFlags(type) & ObjectFlags.Mapped && isGenericIndexType(getConstraintTypeFromMappedType(<MappedType>type));
63566361 }
63576362
63586363 function resolveStructuredTypeMembers(type: StructuredType): ResolvedType {
@@ -6458,10 +6463,7 @@ namespace ts {
64586463 getBaseConstraintOfType(type);
64596464 }
64606465
6461- function getConstraintOfTypeParameter(typeParameter: TypeParameter, typeStack?: Type[]): Type {
6462- if (typeStack) {
6463- return !contains(typeStack, typeParameter) && getConstraintFromTypeParameter(typeParameter);
6464- }
6466+ function getConstraintOfTypeParameter(typeParameter: TypeParameter): Type {
64656467 return hasNonCircularBaseConstraint(typeParameter) ? getConstraintFromTypeParameter(typeParameter) : undefined;
64666468 }
64676469
@@ -6503,23 +6505,23 @@ namespace ts {
65036505 * circularly references the type variable.
65046506 */
65056507 function getResolvedBaseConstraint(type: TypeVariable | UnionOrIntersectionType): Type {
6506- let typeStack: Type[];
65076508 let circular: boolean;
65086509 if (!type.resolvedBaseConstraint) {
6509- typeStack = [];
65106510 const constraint = getBaseConstraint(type);
65116511 type.resolvedBaseConstraint = circular ? circularConstraintType : getTypeWithThisArgument(constraint || noConstraintType, type);
65126512 }
65136513 return type.resolvedBaseConstraint;
65146514
65156515 function getBaseConstraint(t: Type): Type {
6516- if (contains(typeStack, t )) {
6516+ if (!pushTypeResolution(t, TypeSystemPropertyName.ResolvedBaseConstraint )) {
65176517 circular = true;
65186518 return undefined;
65196519 }
6520- typeStack.push(t);
65216520 const result = computeBaseConstraint(t);
6522- typeStack.pop();
6521+ if (!popTypeResolution()) {
6522+ circular = true;
6523+ return undefined;
6524+ }
65236525 return result;
65246526 }
65256527
@@ -6556,7 +6558,7 @@ namespace ts {
65566558 const baseIndexedAccess = baseObjectType && baseIndexType ? getIndexedAccessType(baseObjectType, baseIndexType) : undefined;
65576559 return baseIndexedAccess && baseIndexedAccess !== unknownType ? getBaseConstraint(baseIndexedAccess) : undefined;
65586560 }
6559- if (isGenericMappedType(t, typeStack )) {
6561+ if (isGenericMappedType(t)) {
65606562 return emptyObjectType;
65616563 }
65626564 return t;
0 commit comments