When using redux-saga
, flow gives me weird errors, e.g. #regarding next
src/sagas.js:11
11: export function* requestDataCreation({ data }: DataCreationRequestedAction) {
^ next of function body. Missing annotation
src/sagas.js:11
11: export function* requestDataCreation({ data }: DataCreationRequestedAction) {
^ yield of function body. Missing annotation
code:
export function* requestDataCreation({ data }: DataCreationRequestedAction) {
try {
const token = yield call(getAuthToken)
const res = yield call(createData, data, token);
yield put(dataCreationSuccessful(results));
} catch (err) {
console.warn(err)
}
}
export function* dataSagas() {
yield* takeEvery(DATA_CREATION_REQUESTED, requestDataCreation);
}
Using flow 0.29
You need to add type annotation for function result in form Generator<Yield, Return, Next>
Also, if not already done, you may want to use the redux-saga libdef file provided by flow-typed
https://github.com/flowtype/flow-typed/tree/master/definitions/npm/redux-saga_v0.11.x
In the test file, you can also see some examples how sagas are being used:
https://github.com/flowtype/flow-typed/blob/master/definitions/npm/redux-saga_v0.11.x/test_redux-saga_0.11.x.js#L661
Thanks for writing up this issue with a clear repro. @vkurchatkin is right, you need to annotate the return type of the generator function. In fact, all exported functions need to be annotated. Flow should correctly infer these type parameters otherwise, per these test cases.
Most helpful comment
Also, if not already done, you may want to use the redux-saga libdef file provided by flow-typed
https://github.com/flowtype/flow-typed/tree/master/definitions/npm/redux-saga_v0.11.x
In the test file, you can also see some examples how sagas are being used:
https://github.com/flowtype/flow-typed/blob/master/definitions/npm/redux-saga_v0.11.x/test_redux-saga_0.11.x.js#L661