Show Menu

TypeScript Cheat Sheet (DRAFT) by

For developers who know Javascript and want to learn Typescript

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Basic Types



var x: any
Basic declar­ation
var x: {a:any; b:any;};
x is an object
var x: Foo;
x is instance of class Foo


Basic parameter
x:() => string
Function that returns string.
Object that contains a and b
Object that is a class of Foo
Optional parameter


function a(x:bool);
function a(x:nu­mber);
function a(x:an­y):­bool{
   return x%2 == 0;


Basic Class

class Goose{
   private b:bool;
   con­str­uct­or(x: number, y:bool = true){
      ­this.a = x;
      ­this.b = y;

var x: Goose = new Goose(50);

Class Inheri­tance

class Suzy extends Goose{
   con­str­uct­or(­public c: string){
      ­sup­er(0, true);

var y: Suzy = new Suzy("f­oo");
consol­e.l­og(y.c + " | " + y.a);

var z: Goose = new Suzy("b­ar")

Interface Example

interface Foo{

class Bar implements Foo{
      ­return false;

var x:Foo = new Bar();

Function Explin­ation

Overload functions with bool and number.

Create new function that takes a number x and returns a bool.

Execute function.

Class Explin­ation

Create a new class.
Public attribute.
Private attribute.
constr­uctor with attributes x and y
y is optional and defaulted to true.

Instan­tiate with x as 50 and use default for y

Inheri­tance Explin­ation

New class that extends Goose
constr­uctor. creates a public var c
calls inherited constr­uctor.

New instance of the class.
Accessing public attribute c and a.

Making a new Goose using class Suzy.

Interface Explin­ation

Create a new Interface
   Which much have function a

Create a new class that implement Foo
   Imp­lement everything in Foo

Create a new instance of type Foo