Click here to Skip to main content
15,885,244 members
Articles / Programming Languages / Typescript

What is TypeScript?

Rate me:
Please Sign up or sign in to vote.
4.86/5 (5 votes)
20 Feb 2014CPOL 16.7K   3  
What is TypeScript?

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.

TypeScript is an open-source language created by Microsoft, announced in October 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 keywords.

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

TypeScript Code

C#
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

C#
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)


Written By
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
This is a Organisation

3 members

Comments and Discussions

 
-- There are no messages in this forum --