Thursday, October 04, 2012

TypeScript brings types to Javascript

One of the things that I generally get frustrated with when I have to code in Javascript is the lack of safety that strongly typed languages such as Delphi bring to the table. Most of the tools, while they offer basic language helpers, do not do much about the structure of your javascript application. There is no "code insight" for Javascript function parameters...at least not for MY code.

One of the latest offerings from Microsoft, as presented by Anders Hejlsberg, is TypeScript. It appears to me that TypeScript is a game changer in the world of Javascript development.

TypeScript is an extension to Javascript. Everything you can do in Javascript, you can also do in TypeScript. TypeScript "compiles" to Javascript, so there is no special plugins that need to be deployed. Its all about adding the missing "type" and providing code gen helpers to make your code cleaner and easier to understand. Its all about adding that little bit more information that will make your (Javascript) applications much easier to maintain.

Looking over what TypeScript does, it makes sense. Its simple enough that it shouldn't take long to learn to apply.

If you do any Javascript development, take a look at TypeScript.

5 comments:

Anonymous said...

A strongly typed language that compiles down to JS, and let's you mix raw JS in as needed. Hmm... is anyone else reminded of Smart?

SKamradt said...

@masonwheeler: Exactly, although the IDE (VisualStudio) for TypeScript is quite nice... once you get used to the monochrome flatness that is the new UI. TypeScript also creates javascript that tends to be leaner than what is currently generated by Smart.

Jørn E. Angeltveit said...

With "Smart linking", "Optimization" and "Obfuscation", the generated Smart code can be pretty lean too. (http://delphitools.info/2012/02/06/small-is-beautiful/)

I don't doubt that the generated TypeScript code is leaner than the generated Smart-code, but remember that you can do OOP stuff in Smart that JavaScript was never designed to do. So to accomplish inheritance and polymorphism and the OOP stuff you would like to do, the Smart compiler actually generates full VMT-handling within the generated code.

Will be interesting to compare the generated code when we release the new prototype based (the JS-way of OOP-ing) JObject... (http://delphitools.info/2012/10/03/re-rooting-object-pascal/)

François said...

I had the very same reaction as Mason at first.

But I see a significant difference:

From what I know, in TypeScript, the language is Javascript with some of the SMS goodness added to it.
While in SMS, the language is a form of ObjectPascal.

In the end, it's a very different skill on the Developer side of things...

Unknown said...

have a look at vcl.js
its a delphi like environment for html5/tyescrit