TypeScript Cheat Sheet
by Chuck via cheatography.com/4027/cs/847/
Basic Types Basic Class Function Explination
number class Goose{ Overload functions with bool and number.
bool a:number; Create new function that takes a number x
private b:bool; and returns a bool.
string
constructor(x: number, y:bool = true){ Execute function.
any
this.a = x;
this.b = y; Class Explination
Declarations
}
Create a new class.
var x: any Basic declaration }
Public attribute.
var x: {a:any; x is an object var x: Goose = new Goose(50);
Private attribute.
b:any;}; constructor with attributes x and y
Class Inheritance
var x: Foo; x is instance of class y is optional and defaulted to true.
Foo class Suzy extends Goose{ Instantiate with x as 50 and use default for
constructor(public c: string){ y
Parameters super(0, true);
} Inheritance Explination
x:any Basic parameter
}
New class that extends Goose
x:() => string Function that returns
var y: Suzy = new Suzy("foo");
constructor. creates a public var c
string.
console.log(y.c + " | " + y.a);
calls inherited constructor.
x:{a:any;‐ Object that contains a and var z: Goose = new Suzy("bar")
New instance of the class.
b:any;} b
Accessing public attribute c and a.
x:Foo Object that is a class of Interface Example
Making a new Goose using class Suzy.
Foo interface Foo{
x?:any Optional parameter a(b:number):bool; Interface Explination
}
Create a new Interface
Function class Bar implements Foo{
Which much have function a
a(b:number){
function a(x:bool); Create a new class that implement Foo
return false;
function a(x:number); Implement everything in Foo
}
function a(x:any):bool{ Create a new instance of type Foo
}
return x%2 == 0;
var x:Foo = new Bar();
}
a(2);
By Chuck Not published yet. Sponsored by Readable.com
cheatography.com/chuck/ Last updated 11th May, 2016. Measure your website readability!
Page 1 of 1. https://readable.com