question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Either CombineEpics typing is misleading or I don't understand something

See original GitHub issue

Do you want to request a feature or report a bug?
I want to report a bug.

Here’s the problem. I have a bunch of modules (store/state, actions, reducer, epic(s), views). If I combine reducers like this:

type Module1State = { .... }
...
type Module2State = { .... }
...
type RootState = {
  m1: Module1State
  m2: Module2State
}
...
const rootReducer: Reducer<RootState> = combineReducers<RootState>({
  m1: module1reducer,
  m2: module2reducer
});

… I get my RootState just like it is shown above.

Now, each module has its own Epic:

type Module1Action = ... | ... | ...
type Module1State = { .... }
...
const m1Epic: Epic<Module1Action, Module1State>

Okay. The problem appears when I want to combine such Epics:

import { m1Epic, m1ActionType, m1State } from './m1';
import { m2Epic, m2ActionType, m2State } from './m2';
...
type RootAction = m1ActionType | m2ActionType
type RootState = {
  m1: m1State
  m2: m2State
}
...
const store = createStore<RootAction>(
  rootReducer,
  applyMiddleware(
    createEpicMiddleware(
      combineEpics<RootAction, RootState>(m1Epic, m2Epic)
    )
  )
);

This will not compile because according to https://github.com/redux-observable/redux-observable/blob/master/index.d.ts#L51 combineEpics takes type S for Root State Type. Therefor, RootState is not assignable to m1State or m1State

Therefore, it’s either me being stupid and doing something wrong or there’s an issue with the type signatures…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rgbkrkcommented, Nov 7, 2017

In the above example it’s:

CONTENTS_ACTION = LOAD_ACTION | SAVE_ACTION

Whereas in the current code it’s ALL_ACTIONS.

1reaction
rgbkrkcommented, Sep 12, 2017

Yeah, that’s correct. What I end up doing, at least because I’m using FlowType is:

export function loadEpic(
  action$: ActionsObservable<CONTENTS_ACTION>,
  store: Store<*, *>
) {
  return action$
    .ofType("LOAD")
    .do((action: LOAD_ACTION) => {
      // If there isn't a filename, save-as it instead
      if (!action.filename) {
        throw new Error("save needs a filename");
      }
    })

since it lets me carve out the types within the operators just fine.

The reason it tends to be useful to have the action$ all available is that you can use other actions to end certain streams.

.takeUntil(action$.ofType('CANCEL_LOAD').filter(action => action.id === someID))
Read more comments on GitHub >

github_iconTop Results From Across the Web

redux-observable/redux-observable - Gitter
combineEpics is just a merge. so all yours epics become one big observable. ofType is just a helper function that applies a filter...
Read more >
Reducers - TS-React-Boilerplate
Reducers. Now we build our business logic, also known as reducers. Stay calm, this will be a bit more complicated than anything before....
Read more >
Redux-Observable's best-practice is an anti-pattern.
I was recently on a project using Redux-Thunk and was astounded by how easy it is to dispatch actions. I get that most...
Read more >
Purely Functional React Signup with Redux-Observable ...
In this tutorial, we'll build a signup UI using React/Redux and three of my favorite libraries: Ramda, Recompose, and Redux-Observable.
Read more >
immerx-observable - npm Package Health Analysis | Snyk
We use a very basic Observable implementation under the hood and exposes a setAdapter function that we can use to transform it into...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found