Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

TypeScript: The New JavaScript?

DZone's Guide to

TypeScript: The New JavaScript?

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

In the last year I did quite a lot of evaluation, prototyping and testing in the HTML5/Web/JavaScript space. For me, as a Java veteran it was (and still is) a quite refreshing experience and a lot of fun. One question I wanted to answer for myself was: Is it possible in a big organization like Siemens to do professional software development using JavaScript + HTML5? My current answer would be: YES, but with a lot of coaching from experienced people who know the best practices regarding language, project structure, module systems, testing, libraries, tools etc. During my activities I took a look at Dart, CoffeeScript and TypeScript.

I have to admit, I like TypeScript a lot. It gives me most of the abstractions that I am used too from my background as Java developer, like classes, modules and interfaces. And I also like the optional strong typing during compile time with corresponding IntelliSense (or “Content Assist” in EclipseSpeak). The idea of TypeScript is to enhance JavaScript by providing these additional abstractions and compile to plain ole JavaScript.

Here a TypeScript example:

class Student {
  fullname : string;
  constructor(public firstname, public middleinitial, public lastname) {
    this.fullname = firstname + " " + middleinitial + " " + lastname;
  }
}
 
interface Person {
  firstname: string;
  lastname: string;
}
 
function greeter(person : Person) {
  return "Hello, " + person.firstname + " " + person.lastname;
}
 
var user = new Student("Kai", "U.", "Toedter");

compiles to the JavaScript

var Student = (function () {
 function Student(firstname, middleinitial, lastname) {
   this.firstname = firstname;
   this.middleinitial = middleinitial;
   this.lastname = lastname;
   this.fullname = firstname + " " + middleinitial + " " + lastname;
 }
 return Student;
})();
 
function greeter(person) {
  return "Hello, " + person.firstname + " " + person.lastname;
}
 
var user = new Student("Kai", "U.", "Toedter");

TypeScript was created by Microsoft (Anders Hejlsberg) and is licensed under Apache 2.0. The main Web resource is typescriptlang.org. Here you find all information and you can play around live with a nice editor (seeing the original TypeScript and the compiled JavaScript). Currently the TypeScript compiler runs either as a node.js module or using Windows Scripting host. As it is from Microsoft, no one will be surprised that Visual Studio actually has the best IDE support for TypeScript. But the current RC release of JetBrain’s WebStorm also has TypeScript support.

There is no Eclipse-Plugin so far. Recently I tried to write one using Rhino but I got stuck and gave up. But probably people from the Eclipse community who have more experience with integrating editors, content assist etc. might want to give TypeScript a try :)

What do you think about TypeScript?

Have Fun!

Kai



Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Kai Tödter, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}