const fn = (Y: ?() => void) => Y && setTimeout(() => Y(), 10)
^--
this code gives me an error saying Y might be null or undefined -- when in fact, there's no way it could be.
Another example of this bug:
```js
const x = (n: number) => 10
const fn2 = (Y: ?number) => Y && (() => x(Y))
````
It again things that Y might somehow be null/undefined inside the closure.
Flow is pessimistic about refinements, it considers that every function call could modify Y. As for a fix, you can use a const binding
const fn = (Y: ?() => void) => {
const f = Y
f && setTimeout(() => f(), 10)
}
Related
I get being cautious w/ object members, but in this case flow should be able to trivially determine that nothing can modify Y
Any update on this issue? Will it be fixed soon?
Most helpful comment
I get being cautious w/ object members, but in this case flow should be able to trivially determine that nothing can modify Y