Last active
August 29, 2015 14:22
-
-
Save bartoszbobin/d2558314a1210ba9e4de to your computer and use it in GitHub Desktop.
TypeScript - types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = () => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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