Skip to content

Array destructuring puts declaration after assignment #7691

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

Closed
sixinli opened this issue Mar 26, 2016 · 2 comments
Closed

Array destructuring puts declaration after assignment #7691

sixinli opened this issue Mar 26, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@sixinli
Copy link

sixinli commented Mar 26, 2016

TypeScript Version:

1.8.7

Code

let firstValue = 1;
let secondValue = 2;
[firstValue, secondValue] = [3, 4];

Expected behavior:

var firstValue = 1;
var secondValue = 2;
var _a;
_a = [3, 4], firstValue = _a[0], secondValue = _a[1];

Actual behavior:

var firstValue = 1;
var secondValue = 2;
_a = [3, 4], firstValue = _a[0], secondValue = _a[1];
var _a;

Closure Compiler reports _a as unreachable code / use before definition. While this works at runtime, it's not a good practice and looks like a bug in tsc.

@mhegazy
Copy link
Contributor

mhegazy commented Mar 26, 2016

duplicate of #7017

@mhegazy mhegazy closed this as completed Mar 26, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label Mar 26, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Mar 26, 2016

as explained in #7017 (comment), we intend to change this in the future, just to make the code more idiomatic and less machine-generated-like.

@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants