Relate sources to base constraints of mapped type generic indexed accesses#61677
Open
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Open
Conversation
Contributor
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)) ) {
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 #61676