I’m not a JavaScript hater. Really. But I just haven’t really found a lot of connection with the language. Maybe because idiomatic JavaScript (at scale) is a long way from the Kansas of strongly type Java/C# that I’m used to. It’s even a fair way from idiomatic Groovy.

Whatever the case, after having worked on a few medium-sized JavaScript projects (10k+ JS LOC), I find myself getting into a pretty negative headspace whenever I end up writing JavaScript. Maybe partly because I haven’t made the leap to Functional. Maybe partly because the whole toolchain is a re-invent. But whatever the reason, JavaScript never found a place on my Christmas Card list.

But I actually think that’s about to change because…

logo_small

Yup. TypeScript. If JavaScript was written by someone with a Java/C# background, it would look like TypeScript.

A strongly-typed JavaScript with all the features that modern Java/C# devs are used to: strong types, modules, interfaces, classes, inheritance, access modifiers, generics, lambdas, mixins. Totally. Sold.

Best of all, it compiles down to relatively idiomatic ES5 (and even ES3 with some caveats - so you can run it on the XP/IE7 setup that your enterprise clients have :-( ).

And all JavaScript is valid TypeScript - so you’re not sacrificing anything.

And it runs just great on Windows, Mac, Linux with tooling support in all the popular IDEs, editors, and build tools. What’s not to love?

It’s ECMAScript 6, Today!

Even if you’re not sold… you could learn TypeScript just to get used to the new ECMAScript! ECMAScript6 (ES6) is coming sometime mid-year with a pretty good subset of TypeScript features. Well, the finalised ES6 spec is. The browser support will trail that by a while.

But why wait? You can use all that goodnesss today, and have it run shim-free on the crazy wild-west of browser support that some of us need to work with.

Mmmm. So strongly typed…

typescript-all-the-things

Then, why not just go CoffeeScript?

I love this quote by Luke Hoban (one of the TypeScript founders)

“CoffeeScript is to Ruby as TypeScript is to Java/C#/C++.”

And I’ve found that pretty right. I had a look at CoffeeScript and wasn’t fussed. It just didn’t have the language features I was chasing. But TypeScript felt really natural from the get go.

Show us some code…

The best way to get started is to check out the Playground on the TypeScript site. In-browser autocomplete for language syntax, and you can pull down some samples to play with from the dropdown.

I’ve only been playing with TypeScript a few days - so I’m still in the “first love” phase. But if you’re interested in seen a rough tour of what TS look like from a fellow noob, I’m giving a lightening talk tonight at our local Canberra Java User Group. I’m going to demo a little voting app like this…

https://gist.github.com/glenasmith/a72fa467b4a90031c9fb

Looking forward to posting more when I’ve had longer to experiment… And learned a few of the idioms…

But who’d have thought that I’d find a JavaScript derivative that fires me up!

Pumped for the possibilities…