Skip to content

Fix stack overflow in error generation for recursive mapped types#63215

Open
hamzax180 wants to merge 1 commit intomicrosoft:mainfrom
hamzax180:fix/issue-63090
Open

Fix stack overflow in error generation for recursive mapped types#63215
hamzax180 wants to merge 1 commit intomicrosoft:mainfrom
hamzax180:fix/issue-63090

Conversation

@hamzax180
Copy link

Fixes #63090

Bug Description

When a mapped type contains a deeply recursive or circular reference, TypeScript correctly identifies it as an error. However, when generating the diagnostic message (Type_of_property_0_circularly_references_itself_in_mapped_type_1), the compiler calls typeToString(mappedType) to format the error text.

Evaluating typeToString(mappedType) triggers property resolution, which evaluates the symbol's type by calling getTypeOfMappedSymbol again. Since symbol.links.type hasn't been cached with the errorType yet, this hits the same circularity, which attempts to throw another error, triggering typeToString again, leading to an infinite cycle and an eventual RangeError: Maximum call stack size exceeded.

Fix Explanation

This PR breaks the infinite recursion by eagerly caching symbol.links.type = errorType; immediately before calling error(...) and typeToString(mappedType).

When typeToString evaluates the mapped type, it now sees the cached errorType for the symbol and safely halts recursion, generating the correct error message without blowing up the call stack.

Testing

Added the provided reproduction from the issue as a compiler test case:

  • tests/cases/compiler/issue63090.ts
  • Ran hereby baseline-accept so the baseline error generation accurately outputs the circularity error instead of crashing.

@hamzax180
Copy link
Author

@microsoft-github-policy-service agree

@hamzax180 hamzax180 closed this Mar 7, 2026
@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 7, 2026
@hamzax180 hamzax180 reopened this Mar 7, 2026
@github-project-automation github-project-automation bot moved this from Done to Not started in PR Backlog Mar 7, 2026
Copy link
Author

@hamzax180 hamzax180 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all wishes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Crash: RangeError: Maximum call stack size exceeded during type serialization of recursive distributive mapped types

1 participant