Add types for dependency-solver (#46119)

Co-authored-by: Justus Fluegel <klettelars@gmail.com>
This commit is contained in:
Justus Fluegel 2020-07-18 03:03:45 +02:00 committed by GitHub
parent 216303eaa9
commit 68a8df69f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,8 @@
import { addMissingKeys, getDependedBy, getDependencyLines, getEdges, getInDegree, solve } from 'dependency-solver';
const graph: { [key: string]: string[] } = addMissingKeys({ a: ['b', 'c'], c: ['b'] });
const dependedBy_1: { [key: string]: number } = getDependedBy({ a: ['b', 'c'], c: ['b'] });
const dependedBy_2: { [key: string]: number } = getEdges({ a: ['b', 'c'], c: ['b'] });
const dependencyLines_1: Array<[string, string]> = getDependencyLines({ a: ['b', 'c'], c: ['b'] });
const dependencyLines_2: Array<[string, string]> = getInDegree({ a: ['b', 'c'], c: ['b'] });
const solved: string[] = solve({ a: ['b', 'c'], c: ['b'] });

34
types/dependency-solver/index.d.ts vendored Normal file
View File

@ -0,0 +1,34 @@
// Type definitions for dependency-solver 1.0
// Project: https://github.com/haavistu/dependency-solver#readme
// Definitions by: Justus Fluegel <https://github.com/Technikkeller>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Solve dependency graph
*
* @param g dependency graph
*/
export function solve(g: { [key: string]: string[] }): string[];
/**
* Add missing keys for dependencies of other nodes
*
* @param g dependency graph
*/
export function addMissingKeys(g: { [key: string]: string[] }): { [key: string]: string[] };
/**
* Get numbers of dependants for each node
*
* @param g dependency graph
*/
export function getEdges(g: { [key: string]: string[] }): { [key: string]: number };
/**
* Get relations between dependencies, eg. the lines in a tree diagramm
*
* @param g dependency graph
*/
export function getInDegree(g: { [key: string]: string[] }): Array<[string, string]>;
export { getEdges as getDependedBy, getInDegree as getDependencyLines };

View File

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

View File

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