Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly type sagas

I am trying to type sagas. I am using the flow-typed definitions: https://github.com/flowtype/flow-typed/blob/master/definitions/npm/redux-saga_v0.13.x/flow_v0.36.x-v0.37.x/redux-saga_v0.13.x.js

export function* fetchUsers(): Generator<IOEffect, void, any> {
  const users = yield call(UserApi.list)
  yield put(fetchUserSucc(users))
}

But flow keeps complaining:

Identifier IOEffect Could not resolve name

What am I doing wrong?

like image 455
MoeSattler Avatar asked Feb 06 '17 14:02

MoeSattler


2 Answers

You need to import IOEffect from the libdef like this:

import type { IOEffect } from 'redux-saga/effects';

Source: https://github.com/flowtype/flow-typed/issues/645

like image 198
MoeSattler Avatar answered Nov 15 '22 18:11

MoeSattler


Try using this:

import { type Saga } from 'redux-saga';

export function* fetchUsers(): Saga<void> {
  some logic...
}

It works right for me

like image 31
Artem Balamutyuk Avatar answered Nov 15 '22 18:11

Artem Balamutyuk