Last active
December 9, 2020 13:50
-
-
Save JHSeo-git/69035f34dc7b6e1cfd105d1ddd997bdd to your computer and use it in GitHub Desktop.
Adjust typescript for redux-saga yield call type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type StripEffects<T> = T extends IterableIterator<infer E> | |
? E extends Effect | SimpleEffect<any, any> | |
? never | |
: E | |
: never; | |
type DecideReturn<T> = T extends Promise<infer R> | |
? R // If it's a promise, return the promised type. | |
: T extends IterableIterator<any> | |
? StripEffects<T> // If it's a generator, strip any effects to get the return type. | |
: T; // Otherwise, it's a normal function and the return type is unaffected. | |
type CallReturnType<T extends (...args: any[]) => any> = DecideReturn< | |
ReturnType<T> | |
>; | |
const aNumber: CallReturnType<typeof getANumber> = yield call(getANumber); | |
// https://spin.atomicobject.com/2020/08/06/redux-saga-call-effect/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment