Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain freshness on the result of onbject spread operator #12717

Closed
mhegazy opened this issue Dec 7, 2016 · 5 comments
Closed

Maintain freshness on the result of onbject spread operator #12717

mhegazy opened this issue Dec 7, 2016 · 5 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Dec 7, 2016

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 mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Dec 7, 2016
@mhegazy mhegazy added Declined The issue was declined as something which matches the TypeScript vision and removed In Discussion Not yet reached consensus labels Dec 19, 2016
@mhegazy
Copy link
Contributor Author

mhegazy commented Dec 19, 2016

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.

@mhegazy mhegazy closed this as completed Dec 19, 2016
@aaronbeall
Copy link

aaronbeall commented Mar 16, 2017

@mhegazy

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
Copy link

markudevelop commented May 11, 2017

I'm facing the same issue why was that declined?

@mhegazy
Copy link
Contributor Author

mhegazy commented May 17, 2017

An update on this issue. we have revisited the original decision (more in #14853), and some of the patterns involving spread should be flagged now as errors in TS 2.4, see #15908.

@aaronbeall
Copy link

@mhegazy That's great news! Thanks for the update!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants