Monday, January 04, 2016

TypeScript and NodeJS, I'm sold

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript, the way you expect it to be.
I’ve heard of it a long time ago, but recently with TypeScript 1.7 it got async functions, which means you can awaitasynchronous function calls, similarly to C#, Vala, Go and other languages with syntax support for concurrency. That makes coroutines a pleasant experience compared to plain JavaScript. That’s also the main reason why I didn’t choose Dart.
I’m writing a NodeJS application so I decided to give it a go. Here’s my personal tour of TypeScript and why I’m sold to using it.

Does it complain when using undeclared variables?

console.log(foo);
Cannot find name 'foo'.
Sold!

Does it infer types?

var foo = 123;
foo = "bar";
Type 'string' is not assignable to type 'number'.
Sold!

Does it support async arrow functions?

async function foo() {
}
var bar = async () => { await (foo); };
Sold!

Does it support sum types?

var foo: number | string;
foo = 123;
foo = "bar";
Sold!

Does it play nice with CommonJS/AMD imports and external libraries?

Yes, it does very well. Sold!

Is it easy to migrate from and to JavaScript?

Yes. TypeScript makes use of latest ECMAScript features in its syntax when possible, so that JavaScript -> TypeScript is as painless as possible. Sold!
Also to go back from TypeScript to JavaScript, either use the generated code, or remove all the type annotations in the code by yourself.

Does it have non-nullable variables?

No. This is mostly due to the JavaScript nature though. But I’m sure the TypeScript community will come up with a nice solution throughout this topic.

I’m going to use TypeScript wherever I can in this new year instead of plain JavaScript. In particular, I’m rewriting my latest NodeJS application in TypeScript right now.
I hope it will be a great year for this language. The project is exceptionally active, and I hope to contribute back to it.

14 comments:

Emmanuel said...

Hey there, note that Dart has supported async/await for a while now too:

https://www.dartlang.org/articles/beyond-async/

Unknown said...

Was using typescript with npm-ramda and found that its slowing me down. Typescript doesn't understand currying

pandith13 said...

Nice post!
SRI ANNAPOORNESHAWARI ASTROLOGY CENTER.Best Astrologer In Virginia

shri chakram astro centre said...

Nice Post! I liked it.

SRICHAKRAM ASTROLOGY.Best Astrologer In Shivamogga

Elena James said...

The Original Forex Trading System: roboforex login Is The Original Forex Trading System. It Is 100% Automated And Provides An Easy-to-follow Trading System. You Get Access To Real-time Signals, Proven Methods, And A Money-back Guarantee.

Vasudeva said...

Good post thanks for share information.
SRIKRISHANA ASTROLOGY.Best Astrologer In Bagalkot

DurgaAnugarha said...

Nice and useful blog.

DURGAANUGARHA ASTROLOGY.Best Astrologer In indiranagar

abhiramindia said...

Thanks for sharing!

ABHIRAM ASTROLOGY CENTER.Best Astrologer In manitoba

Sudharshan Bhat guruji said...

Very good article,Thank you
For Astrological service contact Shri Durga astro center,They gives
Best Astrologer in Belgaum

Service Providers said...

Thank you for posting such useful post.
For Best Housekeeping Services in Bangalore.Contact us.

MS Groups Resorts said...

Thank you for sharing such detailed information.
Visit Resorts Near Electronic City.

Zanaib said...

The price of this infighting is that we are unlikely to get a substantive legislative response to the threat of cyberterrorism any time soon. Ph.D. in Cybersecurity in the United States

slot asia said...

slot asia เป็นต้นแบบเกม เว็บไซต์สล็อต สล็อตออนไลน์ ยอดนิยมแล้วก็เป็นที่พึงพอใจอย่างยิ่งสำหรับผู้เล่นเกมสล็อตออนไลน์ในช่วงเวลานี้ด้วยแบบเกม พีจี เป็นเกมที่เล่นได้ง่ายๆ

Vrish said...

Discover Delhi's premier Digital Marketing Institute, offering comprehensive courses curated to hone your digital skills. Our expert-led programs cover SEO, social media, PPC, and more, ensuring a dynamic learning experience. Gain practical insights and industry-relevant knowledge to excel in the fast-paced world of digital marketing. Join us today!
Digital Marketing Institute In Delhi