Skip to content

Instantly share code, notes, and snippets.

@JHSeo-git
Last active December 9, 2020 13:50
Show Gist options
  • Save JHSeo-git/69035f34dc7b6e1cfd105d1ddd997bdd to your computer and use it in GitHub Desktop.
Save JHSeo-git/69035f34dc7b6e1cfd105d1ddd997bdd to your computer and use it in GitHub Desktop.
Adjust typescript for redux-saga yield call type
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