Skip to content

Destructuring strings is supported by TS but not by TSTL/Lua #1429

Open
@lolleko

Description

@lolleko

Because strings are iterable, TS supports destructuring them into individual characters:

const [a, b] = "test"; // a = "t" ; b = "e";

We currently do not support that in TSTL.
We should think about adding support for handling strings in restructuring assignments. At the very least, we should throw a diagnostic that this currently does not work.

Current behavior:

https://typescripttolua.github.io/play/#code/GYVwdgxgLglg9mABMOcAUUAWMDOAuRANzhgBMBKAnKAJxjAHNEBvAKEQ8RoFMoQakAIijdqggNysAvq1YQE1RAG0AhgBpEAIwC6iALzJUacpNYAHOmChp1Wk0A

Epected behaviour a = "t", b = "e";

https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABMOcAUUAWMDOAuRANzhgBMBKAnKAJxjAHNEBvAKEQ8RoFMoQakAIijdqggNysAvq1YQE1RAG0AhgBpEAIwC6iALzJUacpLkK4AG24A6C3AZp1Wk0A

Discovered while fixing #1411

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