Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow: List.filter(Boolean) should refine item type to $NonMaybeType #1200

Closed
wokalski opened this issue Apr 5, 2017 · 0 comments
Closed

Comments

@wokalski
Copy link
Contributor

wokalski commented Apr 5, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants