TypeScript: Difference between revisions

From air
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
http://www.typescriptlang.org/
http://www.typescriptlang.org/


TypeScript offers classes, modules, and interfaces to help you build robust components.
TypeScript offers classes, interfaces, mixins, modules, and generics to help you build robust components.


These features are available at development time for high-confidence application development, but are compiled into simple JavaScript.
These features are available at development time for high-confidence application development, but are compiled into simple JavaScript.

Latest revision as of 21:29, 18 February 2015

http://www.typescriptlang.org/

TypeScript offers classes, interfaces, mixins, modules, and generics to help you build robust components.

These features are available at development time for high-confidence application development, but are compiled into simple JavaScript.

TypeScript types let you define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries.

Handbook: http://www.typescriptlang.org/Handbook

Install

sudo npm install -g typescript

First program

cat > inheritance.ts
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);


tsc inheritance.ts