From ff37e623c0037e388bb4d9f845e688547ea96361 Mon Sep 17 00:00:00 2001 From: Nate Silva Date: Mon, 22 May 2017 12:37:36 -0700 Subject: [PATCH 1/3] Added types for p-settle --- types/p-settle/index.d.ts | 28 ++++++++++++++++++++++++++++ types/p-settle/p-settle-tests.ts | 13 +++++++++++++ types/p-settle/tsconfig.json | 23 +++++++++++++++++++++++ types/p-settle/tslint.json | 1 + 4 files changed, 65 insertions(+) create mode 100644 types/p-settle/index.d.ts create mode 100644 types/p-settle/p-settle-tests.ts create mode 100644 types/p-settle/tsconfig.json create mode 100644 types/p-settle/tslint.json diff --git a/types/p-settle/index.d.ts b/types/p-settle/index.d.ts new file mode 100644 index 0000000000..2445106c0e --- /dev/null +++ b/types/p-settle/index.d.ts @@ -0,0 +1,28 @@ +// Type definitions for p-settle 2.0 +// Project: https://github.com/sindresorhus/p-settle#readme +// Definitions by: Nate Silva +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface SettledResult { + isFulfilled: boolean; + isRejected: boolean; + /** If the promise was fulfilled, the resolved value */ + value?: T; + /** If the promise was rejected, the reason */ + reason?: any; +} + +/** + * Returns a Promise that is fulfilled when all promises in `input` are settled. + * + * The fulfilled value is an array of objects with the following properties: + * + * * `isFulfilled` + * * `isRejected` + * * `value` or `reason` (Depending on whether the promise fulfilled or rejected) + * + * @param input + */ +declare function pSettle(input: Iterable>): Array>>; + +export = pSettle; diff --git a/types/p-settle/p-settle-tests.ts b/types/p-settle/p-settle-tests.ts new file mode 100644 index 0000000000..c762d3cc8c --- /dev/null +++ b/types/p-settle/p-settle-tests.ts @@ -0,0 +1,13 @@ +import pSettle = require('p-settle'); + +async function f() { + const promises: Array> = []; + for (let index = 0; index < 10; ++index) { + if (index % 3 === 0) { + promises.push(Promise.reject(new Error('i reject you'))); + } else { + promises.push(Promise.resolve('🦄')); + } + } + const results = await pSettle(promises); +} diff --git a/types/p-settle/tsconfig.json b/types/p-settle/tsconfig.json new file mode 100644 index 0000000000..a83a8b4f49 --- /dev/null +++ b/types/p-settle/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "p-settle-tests.ts" + ] +} diff --git a/types/p-settle/tslint.json b/types/p-settle/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/p-settle/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From b5ae0602a23b6957be73c78be4ea1ef4bfd4aefd Mon Sep 17 00:00:00 2001 From: Nate Silva Date: Mon, 22 May 2017 13:24:03 -0700 Subject: [PATCH 2/3] Corrected return value definition --- types/p-settle/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/p-settle/index.d.ts b/types/p-settle/index.d.ts index 2445106c0e..b61d3d5ea0 100644 --- a/types/p-settle/index.d.ts +++ b/types/p-settle/index.d.ts @@ -23,6 +23,6 @@ interface SettledResult { * * @param input */ -declare function pSettle(input: Iterable>): Array>>; +declare function pSettle(input: Iterable>): Promise>>; export = pSettle; From d357ad09ab8188208c88a4b91d9e4ca41b9db896 Mon Sep 17 00:00:00 2001 From: Nate Silva Date: Mon, 22 May 2017 14:18:54 -0700 Subject: [PATCH 3/3] Use the pSettle namespace to export SettledResult --- types/p-settle/index.d.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/types/p-settle/index.d.ts b/types/p-settle/index.d.ts index b61d3d5ea0..26acaccfb1 100644 --- a/types/p-settle/index.d.ts +++ b/types/p-settle/index.d.ts @@ -3,13 +3,15 @@ // Definitions by: Nate Silva // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface SettledResult { - isFulfilled: boolean; - isRejected: boolean; - /** If the promise was fulfilled, the resolved value */ - value?: T; - /** If the promise was rejected, the reason */ - reason?: any; +declare namespace pSettle { + interface SettledResult { + isFulfilled: boolean; + isRejected: boolean; + /** If the promise was fulfilled, the resolved value */ + value?: T; + /** If the promise was rejected, the reason */ + reason?: any; + } } /** @@ -23,6 +25,6 @@ interface SettledResult { * * @param input */ -declare function pSettle(input: Iterable>): Promise>>; +declare function pSettle(input: Iterable>): Promise>>; export = pSettle;