mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[p-map] introduce typings (#18544)
* [p-map] introduce typings * [p-map] simplify according to review discussion
This commit is contained in:
parent
0860eda60e
commit
2512a18273
18
types/p-map/index.d.ts
vendored
Normal file
18
types/p-map/index.d.ts
vendored
Normal 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;
|
||||
}
|
||||
}
|
||||
18
types/p-map/p-map-tests.ts
Normal file
18
types/p-map/p-map-tests.ts
Normal 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
22
types/p-map/tsconfig.json
Normal 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
1
types/p-map/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user