Fixed mapped type modifier propagation when remapping multiple keys to same property#62927
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where mapped types with key remapping would produce inconsistent modifier propagation when multiple keys remapped to the same output property name. The behavior was dependent on the order of keys in the source type, which was incorrect.
Key changes:
- Added logic to merge optional and readonly modifiers when multiple source keys map to the same target property in mapped types
- Added comprehensive test coverage for both optional and readonly modifier merging scenarios
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/compiler/checker.ts |
Added logic in addMemberForKeyTypeWorker to merge modifiers (optional/readonly) when an existing property is encountered during mapped type key remapping |
tests/cases/compiler/mappedTypeRemappingModifierMerging.ts |
New test case verifying consistent modifier propagation when multiple keys remap to the same property, testing both optional and readonly modifiers |
tests/baselines/reference/mappedTypeRemappingModifierMerging.types |
Baseline file showing expected type inference for the new test |
tests/baselines/reference/mappedTypeRemappingModifierMerging.symbols |
Baseline file showing expected symbol resolution for the new test |
tests/baselines/reference/mappedTypeRemappingModifierMerging.js |
Baseline file showing expected JavaScript output and declaration files |
tests/baselines/reference/mappedTypeRemappingModifierMerging.errors.txt |
Baseline file showing expected readonly property assignment errors |
|
@microsoft-github-policy-service agree |
|
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:
|
Fixes #62318