Skip to content

Instantly share code, notes, and snippets.

@cefn
Created October 16, 2022 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cefn/8f88ceb1b048ea450c01eaab3459b7f7 to your computer and use it in GitHub Desktop.
Save cefn/8f88ceb1b048ea450c01eaab3459b7f7 to your computer and use it in GitHub Desktop.
Infer TReturn type from Generator or AsyncGenerator
export type Returned<
G extends Generator<any, any, any> | AsyncGenerator<any, any, any>
> = G extends Generator<any, infer TReturn, any>
? TReturn
: G extends AsyncGenerator<any, infer AsycTReturn, any>
? AsycTReturn
: never;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment