Skip to content

Commit aa2f1b8

Browse files
Adjust recursion identity for array type references in checker
Agent-Logs-Url: https://github.com/RyanCavanaugh/TypeScript/sessions/dee5edef-e472-4317-8876-e1ca781fb3bf Co-authored-by: RyanCavanaugh <[email protected]>
1 parent 5e4a851 commit aa2f1b8

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/compiler/checker.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25297,14 +25297,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2529725297
// instantiations of that type have the same recursion identity. The default recursion identity is the object
2529825298
// identity of the type, meaning that every type is unique. Generally, types with constituents that could circularly
2529925299
// reference the type have a recursion identity that differs from the object identity.
25300-
function getRecursionIdentity(type: Type): object {
25301-
// Object and array literals are known not to contain recursive references and don't need a recursion identity.
25302-
if (type.flags & TypeFlags.Object && !isObjectOrArrayLiteralType(type)) {
25303-
if (getObjectFlags(type) & ObjectFlags.Reference && (type as TypeReference).node) {
25304-
// Deferred type references are tracked through their associated AST node. This gives us finer
25305-
// granularity than using their associated target because each manifest type reference has a
25306-
// unique AST node.
25307-
return (type as TypeReference).node!;
25300+
function getRecursionIdentity(type: Type): object {
25301+
// Object and array literals are known not to contain recursive references and don't need a recursion identity.
25302+
if (type.flags & TypeFlags.Object && !isObjectOrArrayLiteralType(type)) {
25303+
if (isArrayType(type)) {
25304+
// Array wrappers are common and finite in non-recursive object graphs; track recursion identity through
25305+
// the element type instead of the shared global Array symbol to avoid false positives in deep nesting.
25306+
return getRecursionIdentity(getTypeArguments(type as TypeReference)[0]);
25307+
}
25308+
if (getObjectFlags(type) & ObjectFlags.Reference && (type as TypeReference).node) {
25309+
// Deferred type references are tracked through their associated AST node. This gives us finer
25310+
// granularity than using their associated target because each manifest type reference has a
25311+
// unique AST node.
25312+
return (type as TypeReference).node!;
2530825313
}
2530925314
if (type.symbol && !(getObjectFlags(type) & ObjectFlags.Anonymous && type.symbol.flags & SymbolFlags.Class)) {
2531025315
// We track object types that have a symbol by that symbol (representing the origin of the type), but

0 commit comments

Comments
 (0)