Maintain freshness on the result of onbject spread operator
mhegazy opened this issue ยท 5 comments
mhegazy commented
interface I {
a: number;
b: string;
}
var obj = { c: true };
var i: I = { a: 0, b: "s", c: obj.c };// Error, unknown property c
var i: I = { a: 0, b: "s", ...obj } // No error here.
mhegazy commented
As noted in #2103 (comment), spreading a symbolic name is different from adding the property definition in the object literal. in the later, an excess property is likely an error; in the earlier it is not necessarily one.
aaronbeall commented
Why was this closed? Maybe I didn't understand but this is still an issue:
interface Foo {
a: number;
b: string;
}
declare const stuff: any;
const a: Foo = { a: 1, b: "b" } // Ok
const b: Foo = { a: 1, b: "b", c: "c" } // Error - Ok
const c: Foo = { a: 1, b: "b", c: "c", ...stuff } // No Error - not Ok!
I don't understand why the presence of ...stuff
makes the unknown typed property c
become allowed. If it was part of stuff
I understand this is a "bag or properties" you don't want to error on unknown properties, but why does it allow previous errors to become allowed?
markudevelop commented
I'm facing the same issue why was that declined?
mhegazy commented
aaronbeall commented
@mhegazy That's great news! Thanks for the update!