TypeScript: Difference between revisions

From air
Jump to navigation Jump to search
(Created page with "http://www.typescriptlang.org/ TypeScript offers classes, modules, and interfaces to help you build robust components. These features are available at development time for h...")
 
No edit summary
Line 7: Line 7:
TypeScript types let you define interfaces between software components and to gain insight into the behavior of existing JavaScript libraries.
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=
=Install=

Revision as of 21:27, 18 February 2015

http://www.typescriptlang.org/

TypeScript offers classes, modules, and interfaces 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