diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts new file mode 100644 index 0000000000..159a2e90fb --- /dev/null +++ b/types/co/co-tests.ts @@ -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'); diff --git a/types/co/index.d.ts b/types/co/index.d.ts new file mode 100644 index 0000000000..958c222a14 --- /dev/null +++ b/types/co/index.d.ts @@ -0,0 +1,18 @@ +// Type definitions for co 4.6 +// Project: https://github.com/tj/co#readme +// Definitions by: Doniyor Aliyev +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.1 + +type ExtractType = T extends IterableIterator ? R : never; + +interface Co { + Generator>(fn: F, ...args: Parameters): Promise>>; + default: Co; + co: Co; + wrap: Generator>(fn: F) => (...args: Parameters) => Promise>>; +} + +declare const co: Co; + +export = co; diff --git a/types/co/tsconfig.json b/types/co/tsconfig.json new file mode 100644 index 0000000000..bc5a88eb32 --- /dev/null +++ b/types/co/tsconfig.json @@ -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" + ] +} diff --git a/types/co/tslint.json b/types/co/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/co/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }