Merge pull request #33120 from doniyor2109/co

Added type for `co`
This commit is contained in:
Jessica Franco
2019-02-17 02:45:10 +09:00
committed by GitHub
4 changed files with 72 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import co = require('co');
function* gen(num: number, str: string, arr: number[], obj: object, fun: () => void) {
return num;
}
co(gen, 42, 'forty-two', [42], { value: 42 }, () => {})
.then((num: number) => {}, (err: Error) => {})
.catch((err: Error) => {});
co.default(gen, 42, 'forty-two', [42], { value: 42 }, () => {})
.then((num: number) => {}, (err: Error) => {})
.catch((err: Error) => {});
co.co(gen, 42, 'forty-two', [42], { value: 42 }, () => {})
.then((num: number) => {}, (err: Error) => {})
.catch((err: Error) => {});
co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, () => {})
.then((num: number) => {}, (err: Error) => {})
.catch((err: Error) => {});
// $ExpectError
co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}).then((str: string) => {});
// $ExpectError
co.wrap(gen)();
// $ExpectError
co.wrap(gen)('forty-two');
+18
View File
@@ -0,0 +1,18 @@
// Type definitions for co 4.6
// Project: https://github.com/tj/co#readme
// Definitions by: Doniyor Aliyev <https://github.com/doniyor2109>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.1
type ExtractType<T> = T extends IterableIterator<infer R> ? R : never;
interface Co {
<F extends (...args: any[]) => Generator>(fn: F, ...args: Parameters<F>): Promise<ExtractType<ReturnType<F>>>;
default: Co;
co: Co;
wrap: <F extends (...args: any[]) => Generator>(fn: F) => (...args: Parameters<F>) => Promise<ExtractType<ReturnType<F>>>;
}
declare const co: Co;
export = co;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"co-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }