Skip to content

Fix contextual typing loss for computed string keys under circular mapped-type key constraints (Fixes #65530) - #65546

Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/contextual-type-circular-constraint-65530
Open

刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/contextual-type-circular-constraint-65530

Conversation

@zhengdaodeguL

Copy link
Copy Markdown

Fixes #65530

When a mapped type's key constraint resolves to the error type because its base constraint is circular, resolveMappedTypeMembers treated it as an any key and synthesized a spurious [x: string]: undefined index signature. That signature merged with the contextual type of computed string keys, producing ((el: number) => unknown) & undefined with no call signature, so callback parameters lost their contextual type and were reported as implicitly any (TS7006). This is a 6.0.3 → 7.x regression.

Skip member creation when the key constraint is the error type with a circular base constraint, so such a mapped type contributes no members. Genuine [x: string]: undefined index signatures (real or mapped), legitimate any-keyed mapped types, and unresolved-name key types keep their existing behavior.

Adds a regression test covering the reported repro, the genuine undefined-index controls, any keys, and an unresolved key name.

…pped-type key constraints

When a mapped type's key constraint resolves to the error type because
its base constraint is circular, resolveMappedTypeMembers treated it as
an any key and synthesized a spurious [x: string]: undefined index
signature. That signature merged with the contextual type of computed
string keys, producing ((el: number) => unknown) & undefined and
leaving callback parameters implicitly any (TS7006). Skip member
creation when the key constraint is the error type with a circular base
constraint, so the mapped type contributes no members; genuine
string/any keys and unresolved-name cases are unchanged.

Fixes microsoft#65530

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 17, 2026

This branch has not been deployed

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

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

TS7 regression: callback parameter loses contextual type (TS7006) for a computed string key when the type parameter's constraint references itself

2 participants