Skip to content

Instantly share code, notes, and snippets.

@piglovesyou
Last active May 11, 2021 02:27
Show Gist options
  • Save piglovesyou/15150ce14bf6246ccfc6ba16d9d24986 to your computer and use it in GitHub Desktop.
Save piglovesyou/15150ce14bf6246ccfc6ba16d9d24986 to your computer and use it in GitHub Desktop.
gensync TypeScript type
declare module 'gensync' {
interface GensyncFn<Ps = any, R = any> {
(...args: Ps): Generator<unknown, R>;
sync: (...args: Ps) => R;
async: (...args: Ps) => Promise<R>;
}
function gensync<F extends (...args: any) => any>(obj: {
sync: F;
errback?: any;
async?: any;
}): GensyncFn<Parameters<F>, ReturnType<F>>;
function gensync<G extends (...args: any) => Generator>(
generator: G,
): GensyncFn<
Parameters<G>,
G extends (...args: any) => Generator<any, infer R> ? R : never
>;
export default gensync;
}
@piglovesyou
Copy link
Author

Not sure it's perfect but works locally. Appreciate it if someone finishes it and publishes it on DefinitelyTyped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment