the-dr-lazy / deox

Functional Type-safe Flux Standard Utilities
https://deox.js.org
MIT License
206 stars 12 forks source link

Typescript error if trying to combine only one epic ... #100

Closed JalilArfaoui closed 5 years ago

JalilArfaoui commented 5 years ago

First, thanks for this very neat library !

Here's a weird error when used with redux-observable ... if trying to combineEpics only one epic !

I know combineEpics is useless with only one epic ... but if you have 2 epics, and you want to momentary disable one, it shouldn't be a problem IHMO.

I've reproduced the issue based one the example given in the docs : https://deox.js.org/faq#using-redux-observable-with-deox

Here's my CodeSandbox "fork" : https://codesandbox.io/s/redux-observable-example-4g1lt

The only thing I changed from the given one (https://codesandbox.io/s/redux-observable-example-z6sdk) is to replace combineEpics(fetchAllTodosEpic, addTodoEpic) by combineEpics(addTodoEpic) in todos.ts.

The error then pops all the way in create-store.ts on epicMiddleware.run(rootEpic) :

(alias) const rootEpic: (action$: Observable<{
    type: "TODO_ADD_NEXT";
    payload: {
        title: string;
        completed: any;
    };
} | {
    type: "TODO_ADD_ERROR";
} | {
    type: "TODO_ADD_ERROR";
    payload: any;
    error: true;
} | {
    type: "TODO_ADD_ERROR";
    payload: any;
} | {
    ...;
} | {
    ...;
}>, _state$: Observable<...>, { api }: {
    ...;
}) => Observable<...>
import rootEpic
L'argument de type '(action$: Observable<{ type: "TODO_ADD_NEXT"; payload: { title: string; completed: any; }; } | { type: "TODO_ADD_ERROR"; } | { type: "TODO_ADD_ERROR"; payload: any; error: true; } | { type: "TODO_ADD_ERROR"; payload: any; } | { ...; } | { ...; }>, _state$: Observable<...>, { api }: { ...; }) => Observable<...>' n'est pas attribuable au paramètre de type 'Epic<Action<any>, Action<any>, void, { api: typeof import("/sandbox/src/store/api"); }>'.
  Les types des paramètres '_state$' et 'state$' sont incompatibles.
    Impossible d'assigner le type 'StateObservable<void>' au type 'Observable<{ todos: Todo[]; isFetching: boolean; }>'.
      Les types de la propriété 'operator' sont incompatibles.
        Impossible d'assigner le type 'Operator<any, void>' au type 'Operator<any, { todos: Todo[]; isFetching: boolean; }>'.
          Impossible d'assigner le type 'void' au type '{ todos: Todo[]; isFetching: boolean; }'.ts(2345)

Any insight on this ?

JalilArfaoui commented 5 years ago

Or do you think this is a pure redux-observable typing issue ?

the-dr-lazy commented 5 years ago

Hey @JalilArfaoui, Thank you for your trust and contribution. I don't see any error on codesandbox!

Screen Shot 2019-07-12 at 12 14 35 AM

JalilArfaoui commented 5 years ago

As I said, the error pops in create-store.ts on epicMiddleware.run(rootEpic) :

image

the-dr-lazy commented 5 years ago

Oh, all of my error finding nuclei in my brain was searching around combineEpic.

It's related to https://github.com/redux-observable/redux-observable/issues/592. The error is due to the default void type for the state generic in EpicMiddleware interface in redux-observable (maybe it was intentional!). I have provided a codesandbox with simple epic to explain it.

creaux commented 5 years ago

Any workaround here?

the-dr-lazy commented 5 years ago

It's related to redux-observable @creaux. You can follow it on https://github.com/redux-observable/redux-observable/issues/592.