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

Object Spread should not invoke setter. #13668

Open
HerringtonDarkholme opened this issue Jan 25, 2017 · 4 comments
Open

Object Spread should not invoke setter. #13668

HerringtonDarkholme opened this issue Jan 25, 2017 · 4 comments
Labels
Bug A bug in TypeScript ES Next New featurers for ECMAScript (a.k.a. ESNext)
Milestone

Comments

@HerringtonDarkholme
Copy link
Contributor

HerringtonDarkholme commented Jan 25, 2017

Current stage-3 spec requires object spread should define new properties on rest object, not set value on rest object.

Spec:
http://sebmarkbage.github.io/ecmascript-rest-spread/#AbstractOperations-CopyDataProperties
More readable example:
https://github.com/sebmarkbage/ecmascript-rest-spread/blob/master/Issues.md#setters

TypeScript Version: nightly

Code

let record = { x: 1 };
let obj = { set x(a) { throw new Error(); }, ...record }; // not error
obj.x; // 1

Expected behavior:
No runtime error.

Actual behavior:
Runtime error.

Note: Babel does not define properties by default either.

@RyanCavanaugh
Copy link
Member

Is this a curious issue of spec compliance, or a real-world thing?

@HerringtonDarkholme
Copy link
Contributor Author

Purely compliance issue, I haven't seen any real world problem. Not even in Babel's issue list.

@mhegazy mhegazy added ES Next New featurers for ECMAScript (a.k.a. ESNext) Bug A bug in TypeScript labels Jan 26, 2017
@mhegazy mhegazy added this to the Future milestone Apr 12, 2018
@mgol
Copy link

mgol commented Nov 19, 2018

It's not just a question of spec compliance. First of all, Babel implements this behavior so people migrating from Babel to TypeScript may introduce bugs into their codebases. Secondly, this is important for some security-enhanced environments as it's possible to monkey-patch methods like Object.assign but not syntax like object spread. See the meeting notes of TC39 regarding this decision: https://tc39.github.io/tc39-notes/2014-09_sept-25.html#58-object-rest-destructuring-and-spread-properties

@Andarist
Copy link
Contributor

Andarist commented Sep 9, 2024

@RyanCavanaugh based on some of your more recent comments I think you are not actively interested in issues like this. Perhaps this one can be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript ES Next New featurers for ECMAScript (a.k.a. ESNext)
Projects
None yet
Development

No branches or pull requests

6 participants