Skip to content

TS2783 False Positive #62655

@blake-regalia

Description

@blake-regalia

🔎 Search Terms

TS2783: "... is specified more than once, so this usage will be overwritten", "This spread always overwrites this property"

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about 5.9.3

⏯ Playground Link

https://www.typescriptlang.org/play/?esModuleInterop=false&target=11&jsx=0&verbatimModuleSyntax=true&strictBuiltinIteratorReturn=true&exactOptionalPropertyTypes=true&noImplicitOverride=true&noPropertyAccessFromIndexSignature=true&ts=5.8.3#code/C4TwDgpgBAKgFgSwHYHMoF4oG8BQV9QIAmAXFAM7ABOyKA3HgQDYCGARhE2ZTagwL4McAYwD2SSlGCJU5MvFoBtALoYoKoQDMArkmHAE4qJuREAFMW7VaASjK6iEE0ghEoAH1gy0uAlCoQwNpUSFLe5AB0zubStBgAfGG0EcQY6JjENgI4OI7CrAHGuvqGoTpIZrGo8t52UABuosRauma+BJZQAOSaoqJdADSM+BGj0WY9fV02UAD8s9jDflCsHFzdAGJTQ378Q-xZOEA

💻 Code

type Thing = {
    id: string;
    label: string;
};

const things: Thing[] = [];

function find(id: string): undefined | Thing {
    return things.find(thing => thing.id === id);
}

declare function fun(thing: Thing): void;

fun({
    id: 'foo',
    ...find('foo') ?? {
        label: 'Foo',
    },
});

🙁 Actual behavior

TS2783 on line 15: 'id' is specified more than once is a false positive.

🙂 Expected behavior

Expect no errors. The return type of find('foo') includes undefined, and the right-hand side of the nullish coalescing operation does not override the 'id' property.

Additional information about the issue

No response

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions