Skip to content

Instantly share code, notes, and snippets.

@bartoszbobin
Last active August 29, 2015 14:22
Show Gist options
  • Save bartoszbobin/d2558314a1210ba9e4de to your computer and use it in GitHub Desktop.
Save bartoszbobin/d2558314a1210ba9e4de to your computer and use it in GitHub Desktop.
TypeScript - types
enum Color {
RED, GREEN, BLUE
}
class MyClass {}
var myAny: any;
myAny = 'aaa';
myAny = true;
myAny = 0.00;
myAny = undefined;
myAny = null;
myAny = {};
myAny = () => {};
myAny = new MyClass();
myAny = Color.BLUE;
enum Color {
RED, GREEN, BLUE
}
class MyClass {}
var myBoolean: boolean;
myBoolean = true;
myBoolean = false;
myBoolean = undefined;
myBoolean = null;
myBoolean = Color.BLUE; // wrong
myBoolean = new MyClass(); // wrong
myBoolean = 'aa'; // wrong
myBoolean = 1.00; // wrong
myBoolean = {}; // wrong
myBoolean = () => {}; // wrong
enum Color {
RED, GREEN, BLUE
}
class MyClass {
public param;
}
var myClass: MyClass;
myClass = new MyClass();
myClass = undefined;
myClass = null;
myClass = Color.RED(); // wrong
myClass = 1; // wrong
myClass = true; // wrong
myClass = {}; // wrong
myClass = '1'; // wrong
myClass = () => {}; // wrong
enum Color {
RED, GREEN, BLUE
}
class MyClass { }
var myClass: MyClass;
myClass = Color.RED;
myClass = new MyClass();
myClass = undefined;
myClass = null;
myClass = 1;
myClass = true;
myClass = {};
myClass = '1';
myClass = () => {};
enum Color {
RED, GREEN, BLUE
}
class MyClass { }
var myColor: Color;
myColor = 1; // why it's ok ?"
myColor = undefined;
myColor = null;
myColor = true; // wrong
myColor = new MyClass(); // wrong
myColor = {}; // wrong
myColor = '1'; // wrong
myColor = () => {}; // wrong
interface IClass {
param: number;
}
class MyClass {}
class MyClass1 {
public param: number;
}
class MyClass2 implements IClass {
public param: number;
}
var myClass: IClass;
var myClass: IClass = new MyClass(); // wrong
var myClass: IClass = new MyClass1();
var myClass: IClass = new MyClass2();
var myClass: IClass = undefined;
var myClass: IClass = null;
var myClass: IClass = 1; // wrong
var myClass: IClass = true; //wrong
var myClass: IClass = {}; // wrong
var myClass: IClass = '1'; // wrong
var myClass: IClass = () => {}; // wrong
enum Color {
RED, GREEN, BLUE
}
class MyClass {}
var myNumber: number;
myNumber = -123;
myNumber = 0;
myNumber = 1;
myNumber = 4.00;
myNumber = undefined;
myNumber = null;
myNumber = new MyClass(); // wrong
myNumber = Color.BLUE; // wrong
myNumber = false; // wrong
myNumber = {}; // wrong
myNumber = () => {}; // wrong
enum Color {
RED, GREEN, BLUE
}
class MyClass {}
var myString: string;
myString = 'aaa';
myString = "aaa";
myString = undefined;
myString = null;
myString = new MyClass(); // wrong
myString = Color.BLUE; // wrong
myString = true; // wrong
myString = 0.00; // wrong
myString = {}; // wrong
myString = () => {}; // wrong
enum Color {
RED, GREEN, BLUE
}
class MyClass {}
var myVoid: void;
myVoid = new MyClass(); //wrong
myVoid = Color.BLUE; //wrong
myVoid = 1; //wrong
myVoid = 'aaa'; //wrong
myVoid = true; //wrong
myVoid = undefined; //wrong
myVoid = null; //wrong
myVoid = {}; //wrong
myVoid = () => {}; //wrong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment