Looking for someone with an understanding of the static type checker flow to explain to me where i am taking a wrong turn here. I am trying to understand sub-typing function int
Intersection types in Flow seem to be "badly broken" (https://github.com/facebook/flow/issues/6482#issuecomment-421167167). I can't speak to why test6
and test7
fail but I would like to point out that the type number & string
is an "impossible" type (https://flow.org/en/docs/types/intersections/#toc-impossible-intersection-types). From the documentation:
// @flow
type NumberAndString = number & string;
function method(value: NumberAndString) {
// ...
}
// $ExpectError
method(3.14); // Error!
// $ExpectError
method('hi'); // Error!
What we observe is that neither number
nor string
can satisfy number & string
. Thus, I honestly can't figure out why test1
and test2
would satisfy the type (number & string) => number | string
. I would love some clarity on how intersection types do (or should) work in Flow. For now, though, it seems like they are impractical to use because of their broken nature.