Avoid infinite recursion when instantiating circular inline mapped generic tuple type (#53522)

This commit is contained in:
Mateusz Burzyński
2023-05-24 20:41:04 +02:00
committed by GitHub
parent fefcb81d48
commit 7baf6cd120
4 changed files with 104 additions and 0 deletions

View File

@@ -18926,6 +18926,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const singleton = elementFlags[i] & ElementFlags.Variadic ? t :
elementFlags[i] & ElementFlags.Rest ? createArrayType(t) :
createTupleType([t], [elementFlags[i]]);
// avoid infinite recursion, if the singleton is the type variable itself
// then we'd just get back here with the same arguments from within instantiateMappedType
if (singleton === typeVariable) {
return mappedType;
}
// The singleton is never a generic tuple type, so it is safe to recurse here.
return instantiateMappedType(mappedType, prependTypeMapping(typeVariable, singleton, mapper));
});