Fix mapped type instantiation circularity (#46586)

* Don't obtain constraint if doing so would cause circularity

* Add regression test

* Address CR feedback
This commit is contained in:
Anders Hejlsberg
2021-10-29 14:01:27 -07:00
committed by GitHub
parent 28e3cd3a80
commit b0ab2a54bb
6 changed files with 77 additions and 4 deletions

View File

@@ -16604,7 +16604,8 @@ namespace ts {
if (t.flags & (TypeFlags.AnyOrUnknown | TypeFlags.InstantiableNonPrimitive | TypeFlags.Object | TypeFlags.Intersection) && t !== wildcardType && !isErrorType(t)) {
if (!type.declaration.nameType) {
let constraint;
if (isArrayType(t) || (t.flags & TypeFlags.Any) && (constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, or(isArrayType, isTupleType))) {
if (isArrayType(t) || t.flags & TypeFlags.Any && findResolutionCycleStartIndex(typeVariable, TypeSystemPropertyName.ImmediateBaseConstraint) < 0 &&
(constraint = getConstraintOfTypeParameter(typeVariable)) && everyType(constraint, or(isArrayType, isTupleType))) {
return instantiateMappedArrayType(t, type, prependTypeMapping(typeVariable, t, mapper));
}
if (isGenericTupleType(t)) {