Friday, May 22, 2015

Tuples and destructuring in TypeScript

I have been interested in TypeScript for a while, AngularJS 2 has put it on the developer's map now.

A feature that I look for in any of the new languages now is tuples and destructuring. It makes it easier to return multiple values from a function and assign it to different variables and not an array. TypeScript has it too, example:

TypeScript code:

function returnTuple(a: string, b: string) {
return [b, a];
}
var n = 'World!', m = 'Hello';
var p: string, q: string;
[p, q] = returnTuple(n, m);
alert("result: " + p + " " + q);

Generated Javascript code:

function returnTuple(a, b) {
    return [b, a];
}
var n = 'World!', m = 'Hello';
var p, q;
_a = returnTuple(n, m), p = _a[0], q = _a[1];
alert("result: " + p + " " + q);
var _a;

A run shows an alert with "Hello World!"
A bit like the Go playground, Typescript has one too: http://www.typescriptlang.org/Playground so you can test and play with the code there!

14 comments:

Diya shree said...

I love to stick with all the above-mentioned programming language to reap maximum advantage in this competitive web design and development world. The choice of programming language varies based on the client business needs
Great efforts put it to find the list of articles. Thanks for your article.We are also one of the best sources to learn
Angular JS Training in Chennai | Angular JS Training Institute in Chennai

Tejuteju said...

Really nice blog post. provided a helpful information.I hope that you will post more updates like this AngularJS4 Online Training Hyderabad

ragul ragul said...

Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
Selenium Training in Chennai Tamil Nadu | Selenium Training Institute in Chennai anna nagar | selenium training in chennai velachery

sathish said...


It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.

Selenium training in Chennai

sasitamil said...

I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing..
Believe me I did wrote an post about tutorials for beginners with reference of your blog. 




Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training

Mounika said...

I know you feel more happy when you get things done and best of all those things are your most precious treasure.

Python Online certification training
python Training institute in Chennai
Python training institute in Bangalore

Mounika said...

I would like to thank you for your nicely written post, its informative and your writing style encouraged me to read it till end. Thanks
Python Online certification training
python Training institute in Chennai
Python training institute in Bangalore

Deepali M said...
This comment has been removed by the author.
Tech Guy said...

For Data Science training inbangalore, Visit:
Data Science training in bangalore

Keerthana said...

Giving a Intense of Energy to Making these blog with Much needed Contents, are really Appreciated one.Thanks For these Fantastic articles

For More content Explore Below
python training in chennai | python training in annanagar | python training in omr | python training in porur | python training in tambaram | python training in velachery

Revathi said...

This is a very useful blog.we are knowing a great content and also lots of information.thanks lot!!!!

android training in chennai

android online training in chennai

android training in bangalore

android training in hyderabad

android Training in coimbatore

android training

android online training

Anonymous said...

python training in bangalore | python online Training
artificial intelligence training in bangalore | artificial intelligence online training
machine learning training in bangalore | machine learning online training
uipath-training-in-bangalore | uipath online training
blockchain training in bangalore | blockchain online training
aws training in Bangalore | aws online training
data science training in bangalore | data science online training

deiva said...

Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
oracle training in chennai

oracle training in omr

oracle dba training in chennai

oracle dba training in omr

ccna training in chennai

ccna training in omr

seo training in chennai

seo training in omr

IamLinkfeeder said...

It was really fun reading ypur article. Thankyou very much. # BOOST Your GOOGLE RANKING.It’s Your Time To Be On #1st Page
Our Motive is not just to create links but to get them indexed as will
Increase Domain Authority (DA).We’re on a mission to increase DA PA of your domain
High Quality Backlink Building Service
Boost DA upto 15+ at cheapest
Boost DA upto 25+ at cheapest
Boost DA upto 35+ at cheapest
Boost DA upto 45+ at cheapest