From 743fc6f72c1eff0159021588bf23c60c5ad8b480 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 21:30:24 +0500 Subject: [PATCH 1/6] Added co --- types/co/co-tests.ts | 21 +++++++++++++++++++++ types/co/index.d.ts | 17 +++++++++++++++++ types/co/tsconfig.json | 22 ++++++++++++++++++++++ types/co/tslint.json | 1 + 4 files changed, 61 insertions(+) create mode 100644 types/co/co-tests.ts create mode 100644 types/co/index.d.ts create mode 100644 types/co/tsconfig.json create mode 100644 types/co/tslint.json diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts new file mode 100644 index 0000000000..b610b280aa --- /dev/null +++ b/types/co/co-tests.ts @@ -0,0 +1,21 @@ +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 }, function () {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); + +co.default(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); + +co.co(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); + +co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, function () {}) + .then((num: number) => {}, (err: Error) => {}) + .catch((err: Error) => {}); diff --git a/types/co/index.d.ts b/types/co/index.d.ts new file mode 100644 index 0000000000..0be8976a5f --- /dev/null +++ b/types/co/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for co 4.6 +// Project: https://github.com/tj/co#readme +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +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..dd6af28a07 --- /dev/null +++ b/types/co/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": 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" } From fb4d0a9066e2dbd1730657f46173432ea1168f1c Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 21:37:09 +0500 Subject: [PATCH 2/6] Linter fixes --- types/co/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/co/tsconfig.json b/types/co/tsconfig.json index dd6af28a07..bc5a88eb32 100644 --- a/types/co/tsconfig.json +++ b/types/co/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From 3316c2a06c9309219e710daa6f72e1476eee1681 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 21:41:45 +0500 Subject: [PATCH 3/6] Linter fixes --- types/co/co-tests.ts | 10 +++++----- types/co/index.d.ts | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts index b610b280aa..7348f77394 100644 --- a/types/co/co-tests.ts +++ b/types/co/co-tests.ts @@ -1,21 +1,21 @@ import co = require('co'); -function* gen(num: number, str: string, arr: number[], obj: object, fun: () => void){ +function* gen(num: number, str: string, arr: number[], obj: object, fun: () => void) { return num; } -co(gen, 42, 'forty-two', [42], { value: 42 }, function () {}) +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 }, function () {}) +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 }, function () {}) +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 }, function () {}) +co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, () => {}) .then((num: number) => {}, (err: Error) => {}) .catch((err: Error) => {}); diff --git a/types/co/index.d.ts b/types/co/index.d.ts index 0be8976a5f..59fafd2495 100644 --- a/types/co/index.d.ts +++ b/types/co/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/tj/co#readme // Definitions by: My Self // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.1 type ExtractType = T extends IterableIterator ? R : never; From 932ca670c23e5c64675197f909e53833539bc930 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 21:44:01 +0500 Subject: [PATCH 4/6] Set author name --- types/co/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/co/index.d.ts b/types/co/index.d.ts index 59fafd2495..958c222a14 100644 --- a/types/co/index.d.ts +++ b/types/co/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for co 4.6 // Project: https://github.com/tj/co#readme -// Definitions by: My Self +// Definitions by: Doniyor Aliyev // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.1 From 9104726fb6496af489492deda3d5f054c08a29ae Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 22:34:51 +0500 Subject: [PATCH 5/6] Added error tests --- types/co/co-tests.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts index 7348f77394..b4459a1df2 100644 --- a/types/co/co-tests.ts +++ b/types/co/co-tests.ts @@ -19,3 +19,12 @@ co.co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}) 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'); From 05bf4abb6d526f509dad16505a9bdf058a4867c4 Mon Sep 17 00:00:00 2001 From: doniyor2109 Date: Sat, 16 Feb 2019 22:37:37 +0500 Subject: [PATCH 6/6] Fixes --- types/co/co-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/co/co-tests.ts b/types/co/co-tests.ts index b4459a1df2..159a2e90fb 100644 --- a/types/co/co-tests.ts +++ b/types/co/co-tests.ts @@ -21,7 +21,7 @@ co.wrap(gen)(42, 'forty-two', [42], { value: 42 }, () => {}) .catch((err: Error) => {}); // $ExpectError -co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}).then((str: string) => {}) +co(gen, 42, 'forty-two', [42], { value: 42 }, () => {}).then((str: string) => {}); // $ExpectError co.wrap(gen)();