Skip to content

Commit 8648986

Browse files
committed
Guard against recursion in inferTypeForHomomorphicMappedType
1 parent ef83109 commit 8648986

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ namespace ts {
827827
/** Key is "/path/to/a.ts|/path/to/b.ts". */
828828
let amalgamatedDuplicates: Map<DuplicateInfoForFiles> | undefined;
829829
const reverseMappedCache = createMap<Type | undefined>();
830+
let inInferTypeForHomomorphicMappedType = false;
830831
let ambientModulesCache: Symbol[] | undefined;
831832
/**
832833
* List of every ambient module with a "*" wildcard.
@@ -18267,12 +18268,16 @@ namespace ts {
1826718268
* variable T[P] (i.e. we treat the type T[P] as the type variable we're inferring for).
1826818269
*/
1826918270
function inferTypeForHomomorphicMappedType(source: Type, target: MappedType, constraint: IndexType): Type | undefined {
18271+
if (inInferTypeForHomomorphicMappedType) {
18272+
return undefined;
18273+
}
1827018274
const key = source.id + "," + target.id + "," + constraint.id;
1827118275
if (reverseMappedCache.has(key)) {
1827218276
return reverseMappedCache.get(key);
1827318277
}
18274-
reverseMappedCache.set(key, undefined);
18278+
inInferTypeForHomomorphicMappedType = true;
1827518279
const type = createReverseMappedType(source, target, constraint);
18280+
inInferTypeForHomomorphicMappedType = false;
1827618281
reverseMappedCache.set(key, type);
1827718282
return type;
1827818283
}

0 commit comments

Comments
 (0)