diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7f3c8671de..3938bc24d1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -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 diff --git a/types/promise-map-limit/index.d.ts b/types/promise-map-limit/index.d.ts new file mode 100644 index 0000000000..17e859aec0 --- /dev/null +++ b/types/promise-map-limit/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for promise-map-limit 1.0 +// Project: https://github.com/dbrockman/promise-map-limit +// Definitions by: Joseph Kohlmann +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +export = promiseMapLimit; + +declare function promiseMapLimit( +iterable: Iterable, +concurrency: number, +iteratee: promiseMapLimit.IIteratee +): Promise; + +declare namespace promiseMapLimit { + type IIteratee = (value: T) => Promise | R; +} diff --git a/types/promise-map-limit/promise-map-limit-tests.ts b/types/promise-map-limit/promise-map-limit-tests.ts new file mode 100644 index 0000000000..8d615e57c7 --- /dev/null +++ b/types/promise-map-limit/promise-map-limit-tests.ts @@ -0,0 +1,26 @@ +import mapPromiseLimit = require('promise-map-limit'); + +const promisedStrings = mapPromiseLimit(['foo', 'bar'], 2, s => s); +promisedStrings; // $ExpectType Promise + +const promisedBooleans = mapPromiseLimit([true, false], 2, b => b); +promisedBooleans; // $ExpectType Promise + +const promiseOfPromisedNumbers = mapPromiseLimit( + [{ foo: 1 }, { foo: 2 }], + 2, + value => Promise.resolve(value.foo), +); +promiseOfPromisedNumbers; // $ExpectType Promise + +const promiseNumber = (value: Record): Promise => + new Promise((resolve, reject) => { resolve(value.foo); }); + +(async () => { + const asyncNumbers = await mapPromiseLimit( + [{ foo: 1 }, { foo: 2 }], + 2, + async value => promiseNumber(value), + ); + asyncNumbers; // $ExpectType number[] +})(); diff --git a/types/promise-map-limit/tsconfig.json b/types/promise-map-limit/tsconfig.json new file mode 100644 index 0000000000..a4b0825f25 --- /dev/null +++ b/types/promise-map-limit/tsconfig.json @@ -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" + ] +} diff --git a/types/promise-map-limit/tslint.json b/types/promise-map-limit/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/promise-map-limit/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}