Skip to content

Array destructuring puts declaration after assignment #7691

Closed
@sixinli

Description

@sixinli

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.

Activity

mhegazy

mhegazy commented on Mar 26, 2016

@mhegazy
Contributor

duplicate of #7017

mhegazy

mhegazy commented on Mar 26, 2016

@mhegazy
Contributor

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.

locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sixinli@mhegazy

        Issue actions

          Array destructuring puts declaration after assignment · Issue #7691 · microsoft/TypeScript