Skip to content

Relate sources to base constraints of mapped type generic indexed accesses #61677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented May 8, 2025

fixes #61676

@Copilot Copilot AI review requested due to automatic review settings May 8, 2025 21:50
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog May 8, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label May 8, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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)) ) {

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
Status: Not started
2 participants