As a TypeScript and redux-thunk user, I am curious about the benefits offered by redux-saga. I'd like to give it a shot but am concerned about the call
function and the apparent loss of type safety.
If I do this:
function* invalidateReddit(): SagaIterator {
while (true) {
const {reddit} = yield take(actions.INVALIDATE_REDDIT)
yield call( fetchPosts, reddit )
}
The compiler will not be able to check calls to fetchPosts
. So if I changed the signature to not include the argument...
function fetchPosts() {
// anything here...
}
The invalidateReddit
function, which depends on fetchPosts
, should fail to compile but it will not because call
evaluates my code for me. Is there an established pattern for using this without sacrificing type safety?
UPDATE: The PR at https://github.com/redux-saga/redux-saga/pull/740 looks like it attempts to solve this problem. I will leave this open until it can be closed with a solution.
any
type. It's probably issue with TypeScript itself, but doesn't look like they are working on enabling custom types onyield
statements. – Gurgle