UNPKG

1.39 kBMarkdownView Raw
1# Installation
2> `npm install --save @types/co`
3
4# Summary
5This package contains type definitions for co (https://github.com/tj/co#readme).
6
7# Details
8Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/co.
9## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/co/index.d.ts)
10````ts
11// 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
12// Generator<T, TReturn, TNext> => TReturn
13// Function => ReturnType<Function>
14// others => others
15type ExtractType<I> = I extends { [Symbol.iterator]: () => Iterator<any, infer TReturn, any> } ? TReturn
16 : I extends (...args: any[]) => any ? ReturnType<I>
17 : I;
18
19interface Co {
20 <F extends (...args: any[]) => Iterator<any, any, any>>(fn: F, ...args: Parameters<F>): Promise<
21 ExtractType<ReturnType<F>>
22 >;
23 default: Co;
24 co: Co;
25 wrap: <F extends (...args: any[]) => Iterator<any, any, any>>(
26 fn: F,
27 ) => (...args: Parameters<F>) => Promise<ExtractType<ReturnType<F>>>;
28}
29
30declare const co: Co;
31
32export = co;
33
34````
35
36### Additional Details
37 * Last updated: Mon, 06 Nov 2023 22:41:05 GMT
38 * Dependencies: none
39
40# Credits
41These definitions were written by [Doniyor Aliyev](https://github.com/doniyor2109).
42
\No newline at end of file