[p-map] introduce typings (#18544)

* [p-map] introduce typings

* [p-map] simplify according to review discussion
This commit is contained in:
Dimitri Benin 2017-08-02 01:15:04 +02:00 committed by Sheetal Nandi
parent 0860eda60e
commit 2512a18273
4 changed files with 59 additions and 0 deletions

18
types/p-map/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
// Type definitions for p-map 1.1
// Project: https://github.com/sindresorhus/p-map#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
export = pMap;
declare function pMap<T = any, M = T>(input: Iterable<Input<T>>, mapper: Mapper<T, M>, options?: pMap.Options): Promise<M[]>;
type Input<T> = Promise<T> | PromiseLike<T> | T;
type Mapper<T, R> = (el: T, index: number) => Promise<R> | R;
declare namespace pMap {
interface Options {
concurrency?: number;
}
}

View File

@ -0,0 +1,18 @@
import pMap = require('p-map');
const sites = [
Promise.resolve('sindresorhus'),
true,
1
];
const mapper = (el: number | string | boolean) => Promise.resolve(1);
let num: number;
pMap(sites, mapper, {concurrency: 2}).then(result => {
num = result[3];
});
pMap(sites, mapper).then(result => {
num = result[3];
});

22
types/p-map/tsconfig.json Normal file
View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"p-map-tests.ts"
]
}

1
types/p-map/tslint.json Normal file
View File

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