Created
August 30, 2016 15:19
-
-
Save inlinestyle/4ce813805499167e62ef184092ba8f05 to your computer and use it in GitHub Desktop.
Example of flow disjoint union checking not carrying through closures
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
// @flow | |
type A = { | |
lower: 'a' | |
} | |
type B = { | |
lower: 'b', | |
bMethod: Function | |
} | |
type Alphabet = A | B | |
const method1 = (alphabet: Alphabet) => { | |
if (alphabet.lower === 'b') { | |
alphabet.bMethod(); // this is okay | |
} | |
}; | |
const method2 = (alphabet: Alphabet) => { | |
if (alphabet.lower === 'b') { | |
return () => { | |
alphabet.bMethod(); // this is not okay | |
}; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error message: