Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Stack overflow when strictNullChecks is enabled and a destructuring pattern initializer references its own binding elements.

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

Root cause: getBindingElementTypeFromParentType calls getTypeOfInitializer() to check if the initializer could be undefined. This triggers full type checking of the object literal, which resolves the shorthand property f, which requires the type of binding element f — creating infinite recursion.

Fix: Use getQuickTypeOfExpression() or cached resolvedType instead of getTypeOfInitializer(). If no cached type is available, skip the undefined filtering optimization rather than risk circularity.

Original prompt

Fix the stack overflow that occurs when checking this code (requires --strict on):

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

Your fix must be resilient to syntax variations, e.g.:

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

and non-immediate circularities, e.g.

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

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jan 16, 2026
Copilot AI changed the title [WIP] Fix stack overflow during code type checking Fix stack overflow when checking circular binding element references Jan 16, 2026
Copilot AI requested a review from RyanCavanaugh January 16, 2026 20:13
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