-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yield* call sometimes infers type as Generator #43
Comments
Doing |
works in the sense it stops typescript complaining but breaks runtime behaviour |
I may have caused this in #13 |
Could you formulate this as a dtslist |
Hi @danielnixon you can see an example in #92 . PS more than happy to tidy up the PR if you find it useful |
hi is there any update on this? |
PRs welcome |
I was struggling with this as well, and in the end it was my fault, because I was TLDR: If you have this issue, first go and check all the callees recursively - you might have forgot to change Real example: export function* parseSaga({ threadParse, input }: ParseParams) {
yield put(parseAsync.started())
try {
const result = yield* call(threadParse, input)
yield put(parseAsync.done({ result }))
return result
} catch (error) {
yield put(parseAsync.failed({ error: sanitizeError(error) }))
}
return undefined
}
const parseResult = yield* call(parseSaga, { threadParse, input })
// type of parseResult is inferred as `Generator<bla bla bla>`
Notice how in It is a super silly mistake to make, but took me some time to figure. Hope it helps someone to resolve their type errors. |
Thanks @ivan-aksamentov that's a good insight. I wonder if there's something we can do with eslint to catch that 🤔 |
That might also explain #27 |
I ran into this when using If anyone needs a hack to get around this issue you can do something like this
Avoiding |
@danielnixon I ran into this with Does that seem right? typed-redux-saga/types/index.d.ts Line 567 in bec739d
const raceEffect = race({
timeout: delay(timeoutMs)
}) has type: const raceEffect: SagaGenerator<{
timeout: true | undefined;
}, RaceEffect<SagaGenerator<true, CallEffect<true>>>> but I think it should have the type: const raceEffect: SagaGenerator<{
timeout: true | undefined;
}, RaceEffect<CallEffect<true>>> |
I think I may be running into this issue too. I opened a draft PR with a minimal example as a failing test: #669. Test code repeated here for convenience: // $ExpectType boolean
yield* Effects.call(function* () {
yield* Effects.race({ timeout: Effects.delay(1) });
return true;
}); Test output for convenience:
|
I've had sitatuions where the above example
fetchD1
andfetchD2
are both other sagas that I am calling withcall
butfetchD1
infers the correct type ({ from: string; to: string; featureName: string | undefined; name: string; data: MeasurementCharacteristicPresentation[]; }
) andfetchD2
infers,The difference between the two sagas return,
fetchD1
fetchD2
The text was updated successfully, but these errors were encountered: