Relate sources to base constraints of mapped type generic indexed accesses#61677
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes #61676 by improving how mapped type generic indexed accesses relate to their base constraints. Key changes include adding two new test cases (correlatedUnions3.ts and correlatedUnions2.ts) to confirm expected behavior and updating the type checker (in src/compiler/checker.ts) to correctly handle mapped type generic indexed accesses by using base constraints from target types.
Reviewed Changes
Copilot reviewed 3 out of 7 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/cases/compiler/correlatedUnions3.ts | Adds a new test case to verify behavior with optional callbacks. |
| tests/cases/compiler/correlatedUnions2.ts | Updates an existing test case to reflect stricter callback requirements. |
| src/compiler/checker.ts | Updates the type checking logic to incorporate a new branch for mapped type generic indexed accesses. |
Files not reviewed (4)
- tests/baselines/reference/correlatedUnions2.symbols: Language not supported
- tests/baselines/reference/correlatedUnions2.types: Language not supported
- tests/baselines/reference/correlatedUnions3.symbols: Language not supported
- tests/baselines/reference/correlatedUnions3.types: Language not supported
Comments suppressed due to low confidence (2)
src/compiler/checker.ts:23518
- [nitpick] Consider renaming 'constraint' to a more descriptive name, such as 'baseConstraint' or 'mappedConstraint', to clarify its dual use on both branches in this function.
let constraint;
src/compiler/checker.ts:23520
- Ensure that the branch for mapped type generic indexed accesses handles all edge cases correctly when getBaseConstraintOfType(target) returns a falsy value. It may help to add a clarifying comment and additional tests to verify the intended behavior.
if ( isMappedTypeGenericIndexedAccess(target) && (constraint = getBaseConstraintOfType(target)) && (result = isRelatedTo(source, constraint, RecursionFlags.Target, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) ) {
|
With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies). Next steps for PRs:
|
fixes #61676