I
I
ivan05122020-05-05 09:17:10
typescript
ivan0512, 2020-05-05 09:17:10

How to type redux-saga?

Usually there is no problem finding information about how to type a library, but in the case of sagas, there is almost no information at all.
I did not find anywhere how to type what will return back to the generator. Can it be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
camelCaseVlad, 2020-05-05
@camelCaseVlad

At work, we type with flow, maybe it will help you, with something

// @flow
import { call, put, takeEvery } from 'redux-saga/effects';
import { setupSagaTarget } from '@work-util';
import { fetchApi } from './api';
import * as constants from '../constants'
import * as actions from '../actions';

/**
 * Fetch card data Saga
 * @returns {void}
 */
export function* fetchCData(): Iterator<*> {
  const data = yield call(fetchApi);
  if (data) {
    yield put(actions.success(data));
  }
}

export function* watchFetchRequest(): Iterator<*> {
  yield takeEvery(constants.APP_REQUEST, fetchData);
}

const sagas = [
  setupSagaTarget(watchFetchRequest, true, true),
];

export { sagas };

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question