Skip to content

Instantly share code, notes, and snippets.

@deecewan
Last active August 13, 2018 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deecewan/654be653dcbcc8e1eda6e73da6ad3f9b to your computer and use it in GitHub Desktop.
Save deecewan/654be653dcbcc8e1eda6e73da6ad3f9b to your computer and use it in GitHub Desktop.
This is why flow invalidates type refinements at seemingly arbitrary times
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