kefirjs / kefir

A Reactive Programming library for JavaScript
https://kefirjs.github.io/kefir/
MIT License
1.87k stars 97 forks source link

Flow 0.50.0 throws errors in kefir #245

Closed EvHaus closed 7 years ago

EvHaus commented 7 years ago

After upgrading to Flow 0.50.0 I am now getting the following Flow errors coming from kefir:

node_modules/kefir/dist/kefir.js.flow:40
 40:     next?: (value: V) => any,
                        ^ V. invariant position (expected `V` to occur only covariantly)

node_modules/kefir/dist/kefir.js.flow:41
 41:     error?: (error: E) => any,
                         ^ E. invariant position (expected `E` to occur only covariantly)

node_modules/kefir/kefir.js.flow:40
 40:     next?: (value: V) => any,
                        ^ V. invariant position (expected `V` to occur only covariantly)

node_modules/kefir/kefir.js.flow:41
 41:     error?: (error: E) => any,
                         ^ E. invariant position (expected `E` to occur only covariantly)
mAAdhaTTah commented 7 years ago

There are two articles about this on Flowtype that should help here:

https://flow.org/en/docs/lang/variance/ https://flow.org/en/docs/lang/depth-subtyping/

I think the functions may just need to add + to the generics passed into them.

rpominov commented 7 years ago

I have a fix in #246 , but not sure if it's correct. As far as I understand Flow thinks that this code is unsafe because subscribe() may mutate passed object, and I've tricked Flow to think that It's alright using interface.

See also https://github.com/facebook/flow/issues/2354

/cc @hallettj @AgentME

Macil commented 7 years ago

Yeahh variance errors are fun. I think that pull request looks right.

rpominov commented 7 years ago

Ok, probably should merge it.