Last active
August 13, 2018 04:19
-
-
Save deecewan/654be653dcbcc8e1eda6e73da6ad3f9b to your computer and use it in GitHub Desktop.
This is why flow invalidates type refinements at seemingly arbitrary times
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
class Test { | |
constructor() { | |
this.scrollView = { | |
flash: () => { | |
console.log(this); | |
}, | |
doSomethingElse: () => { | |
console.log('*evil laugh*'); | |
this.scrollView = null; | |
}, | |
} | |
} | |
} | |
const t = new Test(); | |
if (t.scrollView) { | |
t.scrollView.doSomethingElse(); | |
// => *evil laugh* | |
t.scrollView.flash(); // with flow enabled, this line will error, because the refinement is nullfied by the previous function call | |
// => Uncaught TypeError: Cannot read property 'flash' of null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment