Click here to Skip to main content
13,088,711 members (55,479 online)
Click here to Skip to main content
Add your own
alternative version

Stats

11.2K views
3 bookmarked
Posted 20 Feb 2014

What is TypeScript?

, 20 Feb 2014
Rate this:
Please Sign up or sign in to vote.
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

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
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Organisation

3 members


You may also be interested in...

Comments and Discussions

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