Fixed mapped types not being considered as homomorphic with substitution constraints - #63905
Conversation
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
There was a problem hiding this comment.
Pull request overview
Fixes homomorphic mapped-type detection when keyof T is wrapped in a substitution constraint.
Changes:
- Unwraps substitution constraints before detecting homomorphic mapped types.
- Adds regression and distributivity tests with baselines.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Corrects homomorphism detection. |
tsc/testdata/tests/cases/compiler/mappedTypeNotMistakenlyHomomorphic2.ts |
Tests issue #63132. |
tsc/testdata/tests/cases/compiler/mappedTypeHomomorphismWithPriorKeyofTChecks1.ts |
Tests distributive and non-distributive forms. |
tsc/testdata/baselines/reference/compiler/mappedTypeNotMistakenlyHomomorphic2.types |
Records inferred types. |
tsc/testdata/baselines/reference/compiler/mappedTypeNotMistakenlyHomomorphic2.symbols |
Records symbols. |
tsc/testdata/baselines/reference/compiler/mappedTypeHomomorphismWithPriorKeyofTChecks1.types |
Records distributivity results. |
tsc/testdata/baselines/reference/compiler/mappedTypeHomomorphismWithPriorKeyofTChecks1.symbols |
Records symbols. |
tsc/testdata/baselines/reference/compiler/mappedTypeHomomorphismWithPriorKeyofTChecks1.js |
Records emitted output. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Can type-fest be changed regardless? |
I think so - yes. It's just that I usually prefer to open followup PRs when relevant TS PRs land. It's easier to explain to other maintainers the issue being fixed is not hypothethical. I'll create that type-fest PR in a moment though. |
ports microsoft/typescript-go#4596
fixes #63132
What
This PR fixes the issue where conditionals like this
keyof T extends X ? Truthy : Falsywould make{ [K in keyof T: T[K] }not being recognized as homomorphic within theTruthybranch of the conditional type.Extra
This PR comes with a
type-festbreak. I already looked through it... so I'll just quote my original answer here: