Repository navigation
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
Conversation
…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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #65530
When a mapped type's key constraint resolves to the error type because its base constraint is circular,
resolveMappedTypeMemberstreated it as ananykey and synthesized a spurious[x: string]: undefinedindex signature. That signature merged with the contextual type of computed string keys, producing((el: number) => unknown) & undefinedwith no call signature, so callback parameters lost their contextual type and were reported as implicitlyany(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]: undefinedindex signatures (real or mapped), legitimateany-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,
anykeys, and an unresolved key name.