3

I am getting this error when combining my epics:

TS2345: Argument of type 'Epic<SessionAction, GlobalState, any>' is not assignable to parameter of type 'Epic<EmployeeAction, GlobalState, any>'.
Type 'SessionAction' is not assignable to type 'EmployeeAction'.
Types of property 'type' are incompatible.
  Type 'SessionActionTypes' is not assignable to type 'EmployeeActionTypes'.

The following is the code:

import { combineEpics } from 'redux-observable';
import { fetchUserSession } from './sessionEpics';
import { fetchEmployee } from './employeeEpics';

export default combineEpics(
  fetchEmployee,
  fetchUserSession
);
Roy Art
  • 578
  • 5
  • 10
Juan Bernal
  • 97
  • 1
  • 11

3 Answers3

3

I have pretty much the same problem. It seems like typescript grabs the first epic, infers it's type and expect all the rest to be the same.

What I did was cast the first one.

Using your code as example:

import { Observable } from 'rxjs/Observable';
import { AnyAction } from 'redux';
import { combineEpics } from 'redux-observable';
import { fetchUserSession } from './sessionEpics';
import { fetchEmployee } from './employeeEpics';

export default combineEpics(
  fetchEmployee as Observable<AnyAction>,
  fetchUserSession
);
Roy Art
  • 578
  • 5
  • 10
3

Or use combineEpics<any>:

export default combineEpics<any>(
  fetchEmployee,
  fetchUserSession
);
Syscall
  • 19,327
  • 10
  • 37
  • 52
Axel186
  • 541
  • 5
  • 17
1

A better solution might be using the correct types: AnyAction and Observable:

import { AnyAction } from "redux"
import { combineEpics, createEpicMiddleware } from "redux-observable"
import { Observable } from "rxjs"

export const clientMiddleware = createEpicMiddleware(
  combineEpics<AnyAction, Observable<AnyAction>>(
    authenticateEpic(request),
    registerEpic(request)
  ))
squidfunk
  • 391
  • 3
  • 17