microsoft/TypeScript

TS2783 False Positive

Closed this issue ยท 0 comments

๐Ÿ”Ž 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