Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will TypeScript support destructuring assignments?

Tags:

typescript

Will Typescript support destructuring assignments similar to CoffeeScript?

 foo = {x: 1, y: 2, z: 3}
 {x, z} = foo

 # which will yield
 x == 1 && z == 3
like image 380
robkuz Avatar asked Oct 02 '12 07:10

robkuz


People also ask

What is Destructuring in TypeScript?

Tuples in TypeScript are basically a simple Array with definite length and definite Data-type. Destructuring means breaking the structure. In this article we will see how Destructuring of tuple in TypeScript work. Destructuring is simply breaking up into part and assigning to variables.

Can we Destructure function in JavaScript?

The destructuring is also possible for JavaScript Arrays. By default, the object key name becomes the variable that holds the respective value. So no extra code is required to create another variable for value assignment.

How do you Destructure an array of objects in TypeScript?

Destructuring in Objects When destructuring objects, we use curly braces with the exact name of what we have in the object. Unlike in arrays where we can use any variable name to unpack the element, objects allow just the use of the name of the stored data.

Can we do Destructuring on strings?

A nifty use for value destructuring is unpacking string characters. Which comes in handy when doing typical string ops like slugify .


1 Answers

Yes, it will.

See this issue in their bug tracker: http://typescript.codeplex.com/workitem/15

UPDATE: This is now supported.

like image 122
juandopazo Avatar answered Sep 22 '22 16:09

juandopazo