0% found this document useful (0 votes)
17 views1 page

Chuck Typescript

TypeScript quick cheat-sheet

Uploaded by

mychinadaddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views1 page

Chuck Typescript

TypeScript quick cheat-sheet

Uploaded by

mychinadaddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

TypeScript Cheat Sheet

by Chuck via cheatography.com/4027/cs/847/

Basic Types Basic Class Function Explin​ation

number class Goose{ Overload functions with bool and number.


bool a:n​umber; Create new function that takes a number x
private b:bool; and returns a bool.
string
con​str​uct​or(x: number, y:bool = true){ Execute function.
any
​this.a = x;
​this.b = y; Class Explin​ation
Declar​ations
}
Create a new class.
var x: any Basic declar​ation }
Public attribute.
var x: {a:any; x is an object var x: Goose = new Goose(50);
Private attribute.
b:any;}; constr​uctor with attributes x and y
Class Inheri​tance
var x: Foo; x is instance of class y is optional and defaulted to true.
Foo class Suzy extends Goose{ Instan​tiate with x as 50 and use default for
con​str​uct​or(​public c: string){ y
Parameters ​sup​er(0, true);
} Inheri​tance Explin​ation
x:any Basic parameter
}
New class that extends Goose
x:() => string Function that returns
var y: Suzy = new Suzy("f​oo");
constr​uctor. creates a public var c
string.
consol​e.l​og(y.c + " | " + y.a);
calls inherited constr​uctor.
x:{a:a​ny;​‐ Object that contains a and var z: Goose = new Suzy("b​ar")
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​:nu​mbe​r):​bool; Interface Explin​ation
}
Create a new Interface
Function class Bar implements Foo{
Which much have function a
a(b​:nu​mber){
function a(x:bool); Create a new class that implement Foo
​return false;
function a(x:nu​mber); Imp​lement everything in Foo
}
function a(x:an​y):​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

You might also like