diff --git a/types/p-settle/index.d.ts b/types/p-settle/index.d.ts new file mode 100644 index 0000000000..26acaccfb1 --- /dev/null +++ b/types/p-settle/index.d.ts @@ -0,0 +1,30 @@ +// 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 + +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; + } +} + +/** + * 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>): Promise>>; + +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" }