Add type definitions for promise-map-limit package (#25550)

* Add type definitions for map-promise-limit library

* map-promise-limit → promise-map-limit

A typo…sigh. The GitHub repository link to promise-map-limit was previously correct, however.

* Remove additional TSLint rule

Thanks @plantain-00!
This commit is contained in:
Joseph Kohlmann
2018-05-07 13:52:12 -04:00
committed by Sheetal Nandi
parent 0af74afc17
commit 92251a67c8
5 changed files with 70 additions and 0 deletions

1
.github/CODEOWNERS vendored
View File

@@ -3009,6 +3009,7 @@
/types/proj4leaflet/ @BendingBender
/types/project-oxford/ @scsouthw
/types/promise-dag/ @OSjoerdWie
/types/promise-map-limit/ @kohlmannj
/types/promise-pg/ @coldacid
/types/promise-polyfill/ @skysteve
/types/promise-pool/ @vilic

17
types/promise-map-limit/index.d.ts vendored Normal file
View File

@@ -0,0 +1,17 @@
// Type definitions for promise-map-limit 1.0
// Project: https://github.com/dbrockman/promise-map-limit
// Definitions by: Joseph Kohlmann <https://github.com/kohlmannj>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
export = promiseMapLimit;
declare function promiseMapLimit<T, R>(
iterable: Iterable<T>,
concurrency: number,
iteratee: promiseMapLimit.IIteratee<T, R>
): Promise<R[]>;
declare namespace promiseMapLimit {
type IIteratee<T, R> = (value: T) => Promise<R> | R;
}

View File

@@ -0,0 +1,26 @@
import mapPromiseLimit = require('promise-map-limit');
const promisedStrings = mapPromiseLimit(['foo', 'bar'], 2, s => s);
promisedStrings; // $ExpectType Promise<string[]>
const promisedBooleans = mapPromiseLimit([true, false], 2, b => b);
promisedBooleans; // $ExpectType Promise<boolean[]>
const promiseOfPromisedNumbers = mapPromiseLimit(
[{ foo: 1 }, { foo: 2 }],
2,
value => Promise.resolve(value.foo),
);
promiseOfPromisedNumbers; // $ExpectType Promise<number[]>
const promiseNumber = (value: Record<string, number>): Promise<number> =>
new Promise((resolve, reject) => { resolve(value.foo); });
(async () => {
const asyncNumbers = await mapPromiseLimit(
[{ foo: 1 }, { foo: 2 }],
2,
async value => promiseNumber(value),
);
asyncNumbers; // $ExpectType number[]
})();

View File

@@ -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",
"promise-map-limit-tests.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}