Skip to content

Instantly share code, notes, and snippets.

@inlinestyle
Created August 30, 2016 15:19
Show Gist options
  • Save inlinestyle/4ce813805499167e62ef184092ba8f05 to your computer and use it in GitHub Desktop.
Save inlinestyle/4ce813805499167e62ef184092ba8f05 to your computer and use it in GitHub Desktop.
Example of flow disjoint union checking not carrying through closures
// @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
};
}
};
@inlinestyle
Copy link
Author

inlinestyle commented Aug 30, 2016

Error message:

src/flow-disjoint-union-checking.js:23
 23:       alphabet.bMethod(); // this is not okay
                    ^^^^^^^ property `bMethod`. Property not found in
 12: type Alphabet = A | B
                     ^ object type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment