Created
October 1, 2012 16:25
-
-
Save dherman/3812823 to your computer and use it in GitHub Desktop.
TypeScript type system examples
This file contains hidden or 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
// This type-checks and compiles. | |
function Thing(arg : string) { } | |
var obj = new Thing(""); | |
if (true) { | |
obj.x = 3; | |
} | |
obj.x.send(); |
This file contains hidden or 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
// This fails with a type error. | |
function Thing(arg : string) { } | |
var obj = new Thing(42); | |
if (true) { | |
obj.x = 3; | |
} | |
obj.x.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment