Friday, May 20, 2016

TYPESCRIPT - my notes on Pluralsight TypeScript Fundamentals by Dan Wahlin and John Papa

Pluralsight TypeScript Fundamentals by Dan Wahlin and John Papa

TypeScript is a superset of JavaScript

Arrow Functions => (actually it is a "fat" arrow :)
It is a Lambdas.

TypeScript Key Features
Dynamic vs Static

Optional parameter
x? : number

Type and Ambient Declaration
Type declarations: http://definitelytyped.org/
Look for different *.d.ts types files: typescript.codeplex.com
Other 3rd party types files: https://github.com/DefinitelyTyped/DefinitelyTyped


Object Types


Function
Function can take in its parameter object type like this:

var someField = function (rect: {h: number, w?: number}) {
    if (rect.w === undifined) {
          rect.h * rect.h;
    } else {
        rect.h * rect.w;
    }
}

Class
Every class in TypeScript can have:
Constructor, Fields, Properties, Functions

Make variable of whole class and call from that variable static methods:
let greeterMaker: typeof Greeter = Greeter; 
greeterMaker.standardGreeting = "Hey there!";

Properties
Properties are the private members of the class exposed to the exterior by get and set key words.
Check this post: http://blogs.microsoft.co.il/gilf/2013/01/22/creating-properties-in-typescript/

Using a class as an interface (!!!)
As we said in the previous section, a class declaration creates two things: a type representing instances of the class and a constructor function. Because classes create types, you can use them in the same places you would be able to use interfaces.

class Point {
    x: number;
    y: number;
}

interface Point3d extends Point {
    z: number;
}

let point3d: Point3d = {x: 1, y: 2, z: 3};

Rest parameter in TypeScript is what we know like Varargs in Java
someMethod(...someArgs: string)









No comments: