mauron85
mauron85

Reputation: 1544

Redux saga typescript type error in yield all

I'm trying very simple example from redux-saga page.

function* saga(): SagaIterator {
  yield takeEvery(T.GET_CREDENTIALS, getCredentials);
}

export default function* rootSaga() {
  yield all([
    saga(),
  ]);
}

But I get typescript error:

Argument of type 'IterableIterator<RootEffect | TakeEffect | 
ChannelTakeEffect<any> | PutEffect<any> | ChannelPutEf...' is not 
assignable to parameter of type '{ [key: string]: Effect; }'.
Index signature is missing in type 'IterableIterator<RootEffect | 
TakeEffect | ChannelTakeEffect<any> | PutEffect<any> | 
ChannelPutEf...'.

What I'm doing wrong? Thanks for help

Upvotes: 4

Views: 4060

Answers (2)

S&#248;ren Boisen
S&#248;ren Boisen

Reputation: 1706

The examples in the redux-saga repository mostly use this form:

export default function* rootSaga() {
    yield all([
        fork(saga1),
        fork(saga2),
        // ...
    ])
}

See for instance their real-world example. I'm not sure what the point is of using fork instead of call when we are using all around it, since that helper alone should ensure parallel execution.

Upvotes: 2

marcindobry
marcindobry

Reputation: 176

Since links to solutions apparently get downvoted, this is the solution:

export default function* rootSaga() {
  yield all([
    call(saga()),
  ]);
}

Upvotes: 3

Related Questions