Skip to content

Object/Class/Interface destructuring #1473

Open

Description

@jkelleyrtp

[enhancement]

Currently, it seems that destructuring is not supported. It is one of my most used TS features, and I'd like to see it in AssemblyScript.

There are many subtleties to destructuring, but the original TS repo has a well-documented history of changes:

microsoft/TypeScript#1346
microsoft/TypeScript#1463

We would ideally support

var [x, y] = [10, 20];
[x, y] = [y, x];

// and 

interface Foo { bar: f32, baz: f32 };
const { bar } = Foo;

// and

class Foo { bar: f32 = 10.0 };
const { bar } = new Foo();

Activity

  1. MaxGraey commented on Sep 25, 2020

    @MaxGraey
    Member

    @dcodeIO I know in general case it required iterators, but most of time it will be optimized to simple stuffs. For example:

    const arr = [1, 2, 3, 4];
    const [a, b] = arr;
    const [first, second, ...tail] = arr;

    desugared to:

    var arr = [1, 2, 3, 4];
    var a = arr[0], b = arr[1];
    var first = arr[0], second = arr[1], tail = arr.slice(2);

    playground

    And I guess it already could be implemented with some limitations

  2. ExE-Boss commented on Mar 31, 2021

    @ExE-Boss

    @MaxGraey That’s only if you don’t enable the downlevelIteration option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions