Fix TS2783 false positive for union types in object spread expressions#62656
Merged
RyanCavanaugh merged 5 commits intomainfrom Oct 22, 2025
Merged
Fix TS2783 false positive for union types in object spread expressions#62656RyanCavanaugh merged 5 commits intomainfrom
RyanCavanaugh merged 5 commits intomainfrom
Conversation
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix TS2783 false positive issue
Fix TS2783 false positive for union types in object spread expressions
Oct 22, 2025
Member
|
@typescript-bot test it |
Collaborator
Collaborator
|
Hey @RyanCavanaugh, the results of running the DT tests are ready. Everything looks the same! |
Collaborator
|
@RyanCavanaugh Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
Collaborator
|
@RyanCavanaugh Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Collaborator
|
@RyanCavanaugh Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
RyanCavanaugh
approved these changes
Oct 22, 2025
Fix issue ref
andrewbranch
approved these changes
Oct 22, 2025
Copilot AI
added a commit
to microsoft/typescript-go
that referenced
this pull request
Feb 10, 2026
Port of microsoft/TypeScript#62656. Adds CheckFlags.Partial check in checkSpreadPropOverrides so that properties present in only some union constituents don't trigger the "always overwrites" error. Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #61223
Problem
TypeScript incorrectly reported error TS2783 ("'x' is specified more than once, so this usage will be overwritten") when spreading union types in object literals, even when the property wasn't guaranteed to exist in all constituents of the union.
For example, this code incorrectly produced an error:
The error claimed
idwould "always" be overwritten, but this was incorrect. The spread expression evaluates toThing | { label: string }, and the fallback object{ label: 'Foo' }doesn't have anidproperty at all, soidis only overwritten whenfind()returns aThing.Root Cause
The
checkSpreadPropOverridesfunction only checked if a property hadSymbolFlags.Optionalbefore reporting the error. It didn't account for properties that exist in some constituents of a union type but not others. These properties are marked withCheckFlags.Partial(specificallyReadPartialorWritePartial), indicating they're only present in a subset of the union's constituents.Solution
Added an additional check for
CheckFlags.PartialincheckSpreadPropOverrides. Properties marked as partial in union types should not trigger the "always overwrites" error since they don't exist in all code paths.Test Coverage
Added comprehensive test file
spreadUnionPropOverride.tsthat verifies:Thing | { label: string }no longer errors onidThe fix preserves all existing correct behavior while eliminating the false positive for partial properties in union types.
Original prompt
Fixes #62655
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.