Closed
Description
This currently throws a flow error
const list = List.of(1, null);
const nonMaybeList: List<number> = list.filter(Boolean);
It is implemented in Array
in core
. (Although the implementation is not ideal)
For immutable
it can be fixed with appropriate overrides for all types. For instance, for List<T>
the override should look like this.
filter(
predicate: typeof Boolean
): List<$NonMaybeType<T>>;
This works but causes the following flow error:
node_modules/immutable/dist/immutable.js.flow:464
464: ): List<$NonMaybeType<T>>;
^^^^^^^^^^^^^^^^^^^^^^ List. This type is incompatible with
116: ): this;
^^^^ some incompatible instantiation of `this`
In order to resolve it, we have to replace this
from the superclass implementation with _Iterable<K, $NonMaybeType<V>, KI, II, SI>
and then insert overrides for all concrete types analogically to the List
override. The same is done for .map
method. Those workarounds exist because of flow limitations in handling generic class hierarchy.