TypeScript is ES2015

and more!

 

What Large Apps Need

 

Types enable JavaScript developers to use highly-productive development tools and practices like static checking and code refactoring when developing JavaScript applications.​

 

Note: types are optional

 

private trunk: string = 'default text';
public count: number = 0;

var test = function (trunk: String) {
//I do stuff
}

Type...Script - Type annotations allow for faster debugging & reading

 

Just like in ES2015, TS has classes too

 

class ESport {
    private type: string = 'FPS';
    constructor (type: string) {
        this.type = type;
    }
}


class StarCraft extends ESport {
    constructor () {
        super('RTS');
    }

    setType: void (type: string) {
        this.type = type;
    }
}

var sc = new StarCraft();
sc.setType('Real Time Strategy');

Interfaces help create data types

 
interface Type {
   name: string;
   players: number
}

interface Player {
    name?: string;
    skill?: string;
    type?: Type;
    started?: date;
}

class ESport {
    private type: Type = {
        name: 'FPS'
    };
    private Player: Player = {
        name: 'Husky',
        type: type,
        skill: 'Commentator'
    }
    constructor (type: string) {}
}

Decorators - syntactical sugar that extends functionallity of classes and functions

 
function g() {
    console.log("g(): evaluated");
    return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
        console.log("g(): called");
    }
}

class C {
    @g()
    method() {
       // g decorates this function with additional
       // functionallity that makes extending code easier
    }
}

TypeScript is ES2015 and more

By James Brinkerhoff

TypeScript is ES2015 and more

  • 570