Merge pull request #26010 from mrmlnc/npm-run-parallel-limit

[run-parallel-limit] New typings for package
This commit is contained in:
Benjamin Lichtman
2018-06-01 11:20:23 -07:00
committed by GitHub
4 changed files with 97 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
// Type definitions for run-parallel-limit 1.0
// Project: https://github.com/feross/run-parallel-limit
// Definitions by: mrmlnc <https://github.com/mrmlnc>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
declare namespace RunParallelLimit {
type TaskCallback<T> = (err: Error | null, results?: T) => void;
type Task<T> = (callback: TaskCallback<T>) => void;
type TaskObj<T> = Record<string, Task<T>>;
type Callback<T> = (err: Error, results: T) => void;
}
declare function RunParallelLimit<T>(tasks: Array<RunParallelLimit.Task<T>>, limit: number): T[];
declare function RunParallelLimit<T>(tasks: Array<RunParallelLimit.Task<T>>, limit: number, callback: RunParallelLimit.Callback<T[]>): void;
declare function RunParallelLimit<T>(tasks: RunParallelLimit.TaskObj<T>, limit: number): Record<string, T>;
declare function RunParallelLimit<T>(tasks: RunParallelLimit.TaskObj<T>, limit: number, callback: RunParallelLimit.Callback<Record<string, T>>): void;
export = RunParallelLimit;
@@ -0,0 +1,52 @@
import rpl = require('run-parallel-limit');
const tasks: Array<rpl.Task<string>> = [
(callback) => () => callback(null, 'string'),
(callback) => () => callback(new Error('boom')),
// $ExpectError
(callback) => () => callback(null, 1)
];
const justTaskCallback: rpl.TaskCallback<string> = (err, result) => {
// $ExpectType Error | null
err;
// $ExpectType string | undefined
result;
};
justTaskCallback(null, 'string');
justTaskCallback(new Error('boom'));
// $ExpectError
justTaskCallback(null, 1);
rpl(tasks, 5, (err, results) => {
// $ExpectType Error
err;
// $ExpectType string[]
results;
});
// $ExpectType string[]
const results = rpl(tasks, 5);
const tasksObj: rpl.TaskObj<string> = {
one: (callback) => () => callback(null, 'string'),
two: (callback) => () => callback(new Error('boom')),
// $ExpectError
three: (callback) => () => callback(1)
};
rpl(tasksObj, 5, (err, results) => {
// $ExpectType Error
err;
// $ExpectType Record<string, string>
results;
});
// $ExpectType Record<string, string>
const resultsObj = rpl(tasksObj, 5);
+23
View File
@@ -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",
"run-parallel-limit-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }