UNPKG

1.08 kBTypeScriptView Raw
1// Type definitions for co 4.6
2// Project: https://github.com/tj/co#readme
3// Definitions by: Doniyor Aliyev <https://github.com/doniyor2109>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// Minimum TypeScript Version: 3.6
6
7// Since TS 3.6 the checker knows that the correct type of returned values and yielded values https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-6.html
8// Generator<T, TReturn, TNext> => TReturn
9// Function => ReturnType<Function>
10// others => others
11type ExtractType<I> = I extends { [Symbol.iterator]: () => Iterator<any, infer TReturn, any> }
12 ? TReturn
13 : I extends (...args: any[]) => any
14 ? ReturnType<I>
15 : I;
16
17interface Co {
18 <F extends (...args: any[]) => Iterator<any, any, any>>(fn: F, ...args: Parameters<F>): Promise<
19 ExtractType<ReturnType<F>>
20 >;
21 default: Co;
22 co: Co;
23 wrap: <F extends (...args: any[]) => Iterator<any, any, any>>(
24 fn: F,
25 ) => (...args: Parameters<F>) => Promise<ExtractType<ReturnType<F>>>;
26}
27
28declare const co: Co;
29
30export = co;