2

The following correct code produces a Flow error (version 0.93), due to poor Flow support for Symbols:

const iterator: Iterator<Item> = items[Symbol.iterator]();
string [1] is not an array index.

     /private/tmp/flow/flowlib_30af1970/core.js
 [1] 90│   static iterator: string; // polyfill '@@iterator'

I can see two ways to suppress it, neither of which I am happy with. Should I use one of these (if so, which), or is there a better way? If possible, please explain why.

Add a FixMe comment:

// $FlowFixMe
const iterator: Iterator<Item> = items[Symbol.iterator]();

or typecast the array to any:

const iterator: Iterator<Item> = (items: any)[Symbol.iterator]();

Answers submitted to How do I suppress flow symbol errors? from two years ago provide no alternatives either.

(I am seeking ways to eliminate the iterator and use a simple loop, but that's tricky, so ignore the possibility for the purposes of this question)

Nicholas Shanks
  • 10,623
  • 4
  • 56
  • 80

0 Answers0