Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

The checker could recurse infinitely when contextual-typing an object literal initializer for a destructuring with an annotated union (string | number | symbol), leading to a stack overflow on patterns like const { c, f }: string | number | symbol = { c: 0, f };.

Description

  • Track the active binding pattern while computing an initializer’s type so contextual typing doesn’t re-enter the same pattern; references inside that pattern now yield a non-inferrable any instead of recursing.
  • Added regression test destructuringContextualBindingStackOverflow.ts with baselines to cover self-referential destructuring scenarios, including { c, f }, { a, f: (1 + f) }, and cross-referenced { a: f, f: a }.

Testing

  • npx hereby runtests --tests=tests/cases/compiler/destructuringContextualBindingStackOverflow.ts
  • npx hereby runtests-parallel
  • npx hereby lint
  • npx hereby format
Original prompt

Fix the stack overflow that occurs when checking this code:

const { c, f }: string | number | symbol = { c: 0, f };

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@typescript-bot typescript-bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 16, 2026
Copilot AI and others added 2 commits January 16, 2026 18:14
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix stack overflow in type checking code Prevent contextual typing recursion in destructuring initializers Jan 16, 2026
Copilot AI requested a review from RyanCavanaugh January 16, 2026 18:36
Copy link
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

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

@copilot add testcases

const { a, f }: string | number = { a: 0, f: (1 + f) };

and

const { a, f }: string | number = { a: f, f: a };

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 16, 2026

@copilot add testcases

...

Added both cases to the regression test file (commit 0392f4f).

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

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants