TS2783 False Positive
Closed this issue ยท 0 comments
blake-regalia commented
๐ 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
๐ป 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