mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-31 11:07:32 +08:00
Merge pull request #25988 from mrmlnc/npm-run-parallel
[run-parallel] New typings for package
This commit is contained in:
21
types/run-parallel/index.d.ts
vendored
Normal file
21
types/run-parallel/index.d.ts
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// Type definitions for run-parallel 1.1
|
||||
// Project: https://github.com/feross/run-parallel
|
||||
// Definitions by: mrmlnc <https://github.com/mrmlnc>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
declare namespace RunParallel {
|
||||
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 RunParallel<T>(tasks: Array<RunParallel.Task<T>>): T[];
|
||||
declare function RunParallel<T>(tasks: Array<RunParallel.Task<T>>, callback: RunParallel.Callback<T[]>): void;
|
||||
|
||||
declare function RunParallel<T>(tasks: RunParallel.TaskObj<T>): Record<string, T>;
|
||||
declare function RunParallel<T>(tasks: RunParallel.TaskObj<T>, callback: RunParallel.Callback<Record<string, T>>): void;
|
||||
|
||||
export = RunParallel;
|
||||
52
types/run-parallel/run-parallel-tests.ts
Normal file
52
types/run-parallel/run-parallel-tests.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import rpl = require('run-parallel');
|
||||
|
||||
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, (err, results) => {
|
||||
// $ExpectType Error
|
||||
err;
|
||||
|
||||
// $ExpectType string[]
|
||||
results;
|
||||
});
|
||||
|
||||
// $ExpectType string[]
|
||||
const results = rpl(tasks);
|
||||
|
||||
const tasksObj: rpl.TaskObj<string> = {
|
||||
one: (callback) => () => callback(null, 'string'),
|
||||
two: (callback) => () => callback(new Error('boom')),
|
||||
|
||||
// $ExpectError
|
||||
three: (callback) => () => callback(1)
|
||||
};
|
||||
|
||||
rpl(tasksObj, (err, results) => {
|
||||
// $ExpectType Error
|
||||
err;
|
||||
|
||||
// $ExpectType Record<string, string>
|
||||
results;
|
||||
});
|
||||
|
||||
// $ExpectType Record<string, string>
|
||||
const resultsObj = rpl(tasksObj);
|
||||
23
types/run-parallel/tsconfig.json
Normal file
23
types/run-parallel/tsconfig.json
Normal 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-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/run-parallel/tslint.json
Normal file
1
types/run-parallel/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user