Flow reports error:

[flow] [flow] undefined (This type cannot be coerced to string)
(property) IteratorResult.value: any
[Flow]
value: number | void | void
The code executes fine. Is there something wrong with it or we see a flow bug? (I installed latest flow etc. just yesterday.)
The same code for copying:
`// @flow
function * fibonacciSequenceMaker(first, second) {
let [previous, current] = [first, second];
yield previous; yield current;
while (true) {
[previous, current] = [current, previous + current];
yield current;
}
}
function * fibonacciSequenceEvensMaker(first, second, filter) {
for (let thisResult of fibonacciSequenceMaker(first, second))
if (filter(thisResult)) yield thisResult;
}
let result = '';
let generator = fibonacciSequenceEvensMaker(2, 7, (v) => v%2 === 0);
for (let i = 0; i < 20; i++) result += ${generator.next().value},;
console.log(result);
`
value may be actually undefined (When done is true). You either need to check if it's not undefined or check if done is false.
That makes the warning gone:

However, the generator is intended as infinite one. Can you give example how "done" could be true in the same code?
@karlis-repsons flow doesn't know that this is an infinite generator, therefore it thinks that value may be undefined.
Ok, so this would be asking too much: add infinite generators detection to Flow?
Don't know, but you can tell flow that you know for sure that it's not null:
import invariant from 'invariant';
// ...
const value = generator.next().value;
invariant(value != null, 'this should never be null');
or
const value = generator.next().value;
if (value == null) { throw new Error('this should never be null') }
I am too not sure if Flow should try to detect simple infinite generators. But since they could become complicated, thanks for the tip to use invariant.
Ok, so this would be asking too much: add infinite generators detection to Flow?
That's not just complicated, that's truly impossible: https://en.wikipedia.org/wiki/Halting_problem