Skip to content

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

Closed
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Andarist:better-constraint-for-mapped-type-generic-indexed-access-target
Closed

Relate sources to base constraints of mapped type generic indexed accesses#61677
Andarist wants to merge 1 commit intomicrosoft:mainfrom
Andarist:better-constraint-for-mapped-type-generic-indexed-access-target

Conversation

@Andarist
Copy link
Copy Markdown
Contributor

@Andarist Andarist commented May 8, 2025

fixes #61676

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
Copy Markdown
Contributor

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

@typescript-bot
Copy link
Copy Markdown
Collaborator

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:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

A contextually-typed signature coming from correlated union can't be assigned back to source of its contextual type

4 participants