Added types for p-settle

This commit is contained in:
Nate Silva
2017-05-22 12:37:36 -07:00
parent 8013b307c2
commit ff37e623c0
4 changed files with 65 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
// Type definitions for p-settle 2.0
// Project: https://github.com/sindresorhus/p-settle#readme
// Definitions by: Nate Silva <https://github.com/natesilva>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface SettledResult<T> {
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<T>(input: Iterable<PromiseLike<T>>): Array<Promise<SettledResult<T>>>;
export = pSettle;
+13
View File
@@ -0,0 +1,13 @@
import pSettle = require('p-settle');
async function f() {
const promises: Array<Promise<string>> = [];
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);
}
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }