DefinitelyTyped/types/promise-map-limit/promise-map-limit-tests.ts
Joseph Kohlmann 92251a67c8 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!
2018-05-07 10:52:12 -07:00

27 lines
833 B
TypeScript

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[]
})();