Created
January 19, 2018 15:16
-
-
Save peat-psuwit/7f399e9e9900bdd440570b9eca9af816 to your computer and use it in GitHub Desktop.
Flow type refinement
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 = { | |
x: number | |
}; | |
type B = A & { | |
y: string | |
}; | |
type C = A & { | |
z: string | |
}; | |
function f(o: $Exact<A>|$Exact<B>): ?B { | |
if (o.y && o.x > 5) | |
return o; | |
else | |
return null; | |
} | |
function g(o: $Exact<B>): A { | |
return o; | |
} | |
function h(o: ?($Exact<B>|$Exact<C>)) { | |
(o: ?(B|C)); | |
if (o) | |
(o: $Exact<B>|$Exact<C>); | |
if (o) | |
// A. This type is incompatible with union: `B` | `C` | |
(o: B|C); | |
if (o) | |
((o: $Exact<B>|$Exact<C>): B|C); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment