Add types for task-graph-runner (#27371)

This commit is contained in:
Melvin Groenhoff
2018-07-23 20:27:11 +02:00
committed by Andy
parent 655e4406d0
commit c1cddbee9b
4 changed files with 64 additions and 0 deletions

22
types/task-graph-runner/index.d.ts vendored Normal file
View File

@@ -0,0 +1,22 @@
// Type definitions for task-graph-runner 1.0
// Project: https://github.com/thejameskyle/task-graph-runner#readme
// Definitions by: Melvin Groenhoff <https://github.com/mgroenhoff>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export = taskGraphRunner;
declare function taskGraphRunner<Item, Result>(opts: taskGraphRunner.Opts<Item, Result>): Promise<taskGraphRunner.Results<Item, Result>>;
declare namespace taskGraphRunner {
interface Opts<Item, Result> {
graph: Map<Item, Item[]>;
task: (item: Item) => Result;
force?: boolean;
}
interface Results<Item, Result> {
values: Map<Item, Result>;
safe: boolean;
}
}

View File

@@ -0,0 +1,17 @@
import taskGraphRunner, { Opts, Results } from 'task-graph-runner';
const graph = new Map([
["task-a", ["task-d"]],
["task-b", ["task-d", "task-a"]],
["task-c", ["task-d"]],
["task-d", []],
]);
async function task(name: string) {
const result = await Promise.resolve(name);
return result;
}
let results = taskGraphRunner({ graph, task });
results = taskGraphRunner({ graph, task, force: true });

View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"task-graph-runner-tests.ts"
]
}

View File

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