Ted
Ted

Reputation: 1760

Types of parameters 'saga' and 'saga' are incompatible

I have next code:

const sagaMiddleware = createSagaMiddleware(options);
.
.
.
const createdStore = createStore(
    create(),
    state,
    someMiddleware,
  ) as someStore;

createdStore.runSaga = sagaMiddleware.run; // error here

which works fine until upgrade to latest redux-saga 1.1.3 varsion. Now I am getting next error:

Type '<S extends Saga<any[]>>(saga: S, ...args: Parameters<S>) => Task' is not assignable to type '(saga: (() => IterableIterator<any>) | undefined, args: any) => any'.
  Types of parameters 'saga' and 'saga' are incompatible.
    Type '(() => IterableIterator<any>) | undefined' is not assignable to type 'Saga<any[]>'.
      Type 'undefined' is not assignable to type 'Saga<any[]>'.

how it can be fixed?

Upvotes: 2

Views: 593

Answers (1)

Philip Lipman
Philip Lipman

Reputation: 355

I had the same issue using redux-boilerplate-typescript. I ended up doing the following in types/index.d.ts:

import { Saga } from '@redux-saga/types';

then I changed

export interface InjectedStore extends Store {
  injectedReducers: any;
  injectedSagas: any;
  runSaga(
    saga: (() => IterableIterator<any>) | undefined,
    args: any | undefined,
  ): any;
}

to

export interface InjectedStore extends Store {
  injectedReducers: any;
  injectedSagas: any;
  runSaga(
    saga: Saga | (() => IterableIterator<any>) | undefined,
    args: any | undefined,
  ): any;
}

Upvotes: 2

Related Questions