-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
TypeScript Version: Nightly
Search Terms: object rest property binding Object.assign
Code
var y
({ x: { ...y } } = { x: { z: 1 } })
console.log(y.z === 1) // trueExpected behavior:
The code above should print true without crashing.
Actual behavior:
The TypeScript compiler generates this code when targeting ES2017 or below, which is invalid JavaScript:
var y;
({ x: Object.assign({}, y) } = { x: { z: 1 } });
console.log(y.z === 1); // trueAttempting to run this code gives Uncaught SyntaxError: Invalid destructuring assignment target in V8.
Babel roughly generates this code, which works correctly:
var y;
var _x = { x: { z: 1 } };
y = Object.assign({}, _x.x);
console.log(y.z === 1); // trueThis came up because I'm trying to implement the rest/spread proposal for esbuild by following what the TypeScript compiler does. I logged this issue when I discovered the TypeScript compiler isn't a correct implementation.
Playground Link: link
Related Issues:
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone