Click here to Skip to main content
Click here to Skip to main content
Technical Blog

What is TypeScript ?

, 20 Feb 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
TypeScript is just a tool to be used at coding-time to improve the quality of your JavaScript and make it more readable and maintainable. After your TypeScript is compiled to JavaScript, you can use all your other tools—minifiers, packagers, runtime…Read more ›

TypeScript is just a tool to be used at coding-time to improve the quality of your JavaScript and make it more readable and maintainable. After your TypeScript is compiled to JavaScript, you can use all your other tools—minifiers, packagers, runtime loaders, unit test frameworks, and so forth—as you would if you had written the JavaScript from scratch

Type script is an open-source language created by Microsoft, announced in octobre 2012. TypeScript is in the same line as CoffeScript or Dart for example. Optional static typing and class-based POO, TypeScript is designed for development of large applications and transcript it to JavaScript. The different features look like what you have in C# with Primitive type (number, bool, string, ..), generics or the object syntax. The language has the principal features of object with Modules, classes, interface, … but doesn’t have protected and abstract keyword.

At the present time we are at the version 0.9.5 and in the version 1.x the roadmap includes Async/await, Mixins (abstract ? extension method ?) and protected access.

Type script site : http://www.typescriptlang.org/
Test your TypeScript code : http://typescript.io/
Dart site : https://www.dartlang.org/
CoffeeScriptSite : http://coffeescript.org/

 TypeScript code

class Animal {
    constructor(public name: string) { }
    move(meters: number) {
        alert(this.name + " moved " + meters + "m.");
    }
}

class Snake extends Animal {
    constructor(name: string) { super(name); }
    move() {
        alert("Slithering...");
        super.move(5);
    }
}

class Horse extends Animal {
    constructor(name: string) { super(name); }
    move() {
        alert("Galloping...");
        super.move(45);
    }
}

var sam = new Snake("Sammy the Python");
var tom: Animal = new Horse("Tommy the Palomino");

sam.move();
tom.move(34);

Same code in Javascript 

var __extends = this.__extends || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var Animal = (function () {
    function Animal(name) {
        this.name = name;
    }
    Animal.prototype.move = function (meters) {
        alert(this.name + " moved " + meters + "m.");
    };
    return Animal;
})();

var Snake = (function (_super) {
    __extends(Snake, _super);
    function Snake(name) {
        _super.call(this, name);
    }
    Snake.prototype.move = function () {
        alert("Slithering...");
        _super.prototype.move.call(this, 5);
    };
    return Snake;
})(Animal);

var Horse = (function (_super) {
    __extends(Horse, _super);
    function Horse(name) {
        _super.call(this, name);
    }
    Horse.prototype.move = function () {
        alert("Galloping...");
        _super.prototype.move.call(this, 45);
    };
    return Horse;
})(Animal);

var sam = new Snake("Sammy the Python");
var tom = new Horse("Tommy the Palomino");

sam.move();
tom.move(34);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Betclic Tech
Chief Technology Officer Betclic
France France
I am Head of Software Development at Betclic France. I manage the Paris Dev Team, consisting of 35+ talented people, in various technical and functional projects in the fields of sports betting, poker, casino or horse betting.
 
Check out our technical blog at https://techblog.betclicgroup.com
Group type: Organisation

3 members

Follow on   Twitter

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.141022.1 | Last Updated 20 Feb 2014
Article Copyright 2014 by Betclic Tech
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid