Skip to content

Port TS#62656: Fix TS2783 false positive for union types in object spread#2733

Merged
jakebailey merged 2 commits intomainfrom
copilot/fix-ts2783-union-types
Feb 10, 2026
Merged

Port TS#62656: Fix TS2783 false positive for union types in object spread#2733
jakebailey merged 2 commits intomainfrom
copilot/fix-ts2783-union-types

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 10, 2026

Ports microsoft/TypeScript#62656.

checkSpreadPropOverrides reported TS2783 ("specified more than once, so this usage will be overwritten") for properties that only exist in some constituents of a spread union type. These partial properties are marked with CheckFlags.Partial, but the function only checked SymbolFlags.Optional.

// Before: only skipped optional properties
if right.Flags&ast.SymbolFlagsOptional == 0 {

// After: also skip partial properties (present in some but not all union constituents)
if right.Flags&ast.SymbolFlagsOptional == 0 && right.CheckFlags&ast.CheckFlagsPartial == 0 {

Example that previously false-positived:

type Thing = { id: string; label: string };
fun({
    id: 'foo',  // ❌ TS2783: 'id' is specified more than once
    ...find('foo') ?? { label: 'Foo' },  // spread is Thing | { label: string }
});

The { label: 'Foo' } fallback has no id, so the overwrite is not guaranteed — error was incorrect.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

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>
Copilot AI changed the title [WIP] Fix TS2783 false positive for union types in object spread Port TS#62656: Fix TS2783 false positive for union types in object spread Feb 10, 2026
Copilot AI requested a review from jakebailey February 10, 2026 22:48
@jakebailey jakebailey marked this pull request as ready for review February 10, 2026 22:50
Copilot AI review requested due to automatic review settings February 10, 2026 22:50
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

Ports the TypeScript fix for TS2783 false positives when spreading union types where a property exists in only some union constituents (“partial” properties).

Changes:

  • Update checkSpreadPropOverrides to also skip CheckFlags.Partial properties when checking for guaranteed overwrites.
  • Update baseline error output to remove the incorrect TS2783/TS2785 report for the union-spread repro.
  • Remove the corresponding baseline .diff content now that the expected output is aligned.

Reviewed changes

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

File Description
testdata/baselines/reference/submodule/compiler/spreadUnionPropOverride.errors.txt.diff Removes the no-longer-applicable baseline diff for the previously incorrect diagnostic.
testdata/baselines/reference/submodule/compiler/spreadUnionPropOverride.errors.txt Updates expected errors to no longer include the TS2783 false positive for id.
internal/checker/checker.go Fixes the overwrite check by excluding properties marked CheckFlags.Partial (not guaranteed in all union constituents).

@jakebailey jakebailey enabled auto-merge February 10, 2026 23:24
@jakebailey jakebailey added this pull request to the merge queue Feb 10, 2026
Merged via the queue into main with commit c0df2ff Feb 10, 2026
26 checks passed
@jakebailey jakebailey deleted the copilot/fix-ts2783-union-types branch February 10, 2026 23:51
Copilot AI added a commit that referenced this pull request Feb 25, 2026
…read (#2733)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
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.

4 participants