Skip to content

Fixed mapped types not being considered as homomorphic with substitution constraints#4596

Open
Andarist wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix/homomorphic-mapped-types-substitution-constraints
Open

Fixed mapped types not being considered as homomorphic with substitution constraints#4596
Andarist wants to merge 1 commit into
microsoft:mainfrom
Andarist:fix/homomorphic-mapped-types-substitution-constraints

Conversation

@Andarist

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings July 10, 2026 21:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 a TypeScript checker behavior in the Go port so that mapped types remain homomorphic even when their keyof T constraint flows through a substitution type (matching the regression described in microsoft/TypeScript#63132). It also adds a targeted compiler regression test and commits the corresponding reference baselines.

Changes:

  • Unwrap substitution types when detecting a homomorphic mapped type variable, so keyof T extends ... ? { [K in keyof T]: ... } : ... continues to be recognized as homomorphic.
  • Add a new compiler test case reproducing the scenario from the linked upstream issue.
  • Add committed .types and .symbols reference baselines for the new test.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
internal/checker/checker.go Adjusts homomorphic mapped type detection to use the “actual” (unsubstituted) type variable.
testdata/tests/cases/compiler/mappedTypeNotMistakenlyHomomorphic2.ts New regression test covering homomorphic behavior through conditional wrapping.
testdata/baselines/reference/compiler/mappedTypeNotMistakenlyHomomorphic2.types Reference type baseline for the new test.
testdata/baselines/reference/compiler/mappedTypeNotMistakenlyHomomorphic2.symbols Reference symbol baseline for the new test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: Mapped types are no longer homomorphic when wrapped in certain conditional types

2 participants