How to properly type sagas
Asked Answered
D

2

5

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?

Derekderelict answered 6/2, 2017 at 14:32 Comment(0)
D
5

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

Derekderelict answered 7/2, 2017 at 9:59 Comment(1)
It doesn't seem this is valid any more, getting "Cannot import IOEffect because there is no IOEffect export in redux-saga/effects." when I try to do that!Patricide
C
4

Try using this:

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

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

It works right for me

Cookson answered 14/2, 2019 at 8:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.