Function intersections/unions in $ObjMap don't work
This is a:
- Bug Report
Which concerns:
- flow-runtime
What is the current behaviour?
The following code breaks at runtime:
type $DeepShape<O: Object> = Object &
$Shape<$ObjMap<O, (<V: Object>(V) => $DeepShape<V>) & (<V>(V) => V)>>;
type Thing = {
a: string,
b: string,
c: {
a: string,
}
}
type Hello = $DeepShape<Thing>
const hello: Hello = {
b: 'hello',
}
console.log(hello)
The $DeepShape type is from https://github.com/facebook/flow/issues/5262.
What is the expected behaviour?
The code should not break at runtime and should run without type errors.
Which package versions are you using?
0.17.0
This turns out to be due to this part - (<V: Object>(V) => $DeepShape<V>) & (<V>(V) => V) - which is an intersection of two functions. I was surprised to see that Flow supports this because it doesn't appear to be possible to create a real value that satisfies this intersection.
The other option there would be to use a union type instead of an intersection. Then I get the following error:
Mapper must be a function type.
@phpnode
I was surprised to see that Flow supports this because it doesn't appear to be possible to create a real value that satisfies this intersection.
I don't get what you mean, I think any function that deletes some properties of the given object tree when called with an object, or returns a primitive of the same type otherwise, would satisfy that intersection