Flow Cookbook

Gotchas and interesting cases of flow issues
Gotchas and interesting cases of flow issues
This is a platform for User Generated Content. G/O Media assumes no liability for content posted by Kinja users to this platform.

Warning: Array access in flow gives no warning

As it turns out, when you try to access an element in an array, flow will give you no errors, even though the given index might be out of bounds for the array. So accessing an element of Array<T> will always be of type T, and you need to remember yourself to check its existence.

The reasoning given in the docs is:

In order to make this safe, Flow would have to mark every single array access as “possibly undefined”.

Flow does not do this because it would be extremely inconvenient to use. You would be forced to refine the type of every value you get when accessing an array.

Advertisement

And here’s an example.

The Marciverse awaits

Share This Story

Get our newsletter