From 92251a67c8ffa8420028a2dd2926528c38c7ce92 Mon Sep 17 00:00:00 2001 From: Joseph Kohlmann Date: Mon, 7 May 2018 13:52:12 -0400 Subject: [PATCH] Add type definitions for promise-map-limit package (#25550) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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! --- .github/CODEOWNERS | 1 + types/promise-map-limit/index.d.ts | 17 ++++++++++++ .../promise-map-limit-tests.ts | 26 +++++++++++++++++++ types/promise-map-limit/tsconfig.json | 23 ++++++++++++++++ types/promise-map-limit/tslint.json | 3 +++ 5 files changed, 70 insertions(+) create mode 100644 types/promise-map-limit/index.d.ts create mode 100644 types/promise-map-limit/promise-map-limit-tests.ts create mode 100644 types/promise-map-limit/tsconfig.json create mode 100644 types/promise-map-limit/tslint.json 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" +}