Last active
May 11, 2021 02:27
-
-
Save piglovesyou/15150ce14bf6246ccfc6ba16d9d24986 to your computer and use it in GitHub Desktop.
gensync TypeScript type
This file contains hidden or 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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure it's perfect but works locally. Appreciate it if someone finishes it and publishes it on DefinitelyTyped.