Last active
December 15, 2015 09:59
-
-
Save t0yv0/5242309 to your computer and use it in GitHub Desktop.
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
// Example 1: `any` allows unsafe casts | |
var x : any = 1; | |
x(); | |
// Example 2: subtyping on functions allows unsafe casts | |
interface I1 { x: number; } | |
interface I2 { x: number; y: number; } | |
function f(g: (x: I1) => void) { g({x: 1}); } | |
f(function (x: I2) { console.log(x.y); }) | |
// Example 3: type system ignores closing over `this`: | |
class C { | |
n: number; | |
constructor () { | |
this.n = 0; | |
} | |
next() { | |
var k = this.n; | |
this.n = k + 1; | |
return k; | |
} | |
} | |
function fc(g: () => number) { | |
console.log(g()); | |
console.log(g()); | |
console.log(g()); | |
} | |
var c = new C(); | |
fc(c.next); | |
fc(c.next); | |
fc(c.next); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment