mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Adding support for viz.js (#41105)
* Adding support for viz.js * fixing type capitalization
This commit is contained in:
parent
7570086826
commit
b6598369a5
23
types/viz.js/common.d.ts
vendored
Normal file
23
types/viz.js/common.d.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
interface Options {
|
||||
format?: string;
|
||||
engine?: string;
|
||||
files?: string[];
|
||||
images?: string[];
|
||||
yInvert?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface defines the shape of an object that is held by the caller.
|
||||
* This `Module` was created by emscripten, and is therefore largely arcane.
|
||||
* This currently just lists a subset of what is defined in `Module`.
|
||||
*/
|
||||
interface Module {
|
||||
run(): void;
|
||||
}
|
||||
|
||||
type RenderFunction = (instance: Module, src: string, options: Options) => string;
|
||||
|
||||
declare class Viz {
|
||||
constructor(arg: { Module: Module; render: RenderFunction });
|
||||
renderString(src: string, options?: Options): Promise<string>;
|
||||
}
|
||||
3
types/viz.js/full.render.js.d.ts
vendored
Normal file
3
types/viz.js/full.render.js.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/// <reference path="common.d.ts" />
|
||||
export const Module: Module;
|
||||
export function render(instance: Module, src: string, options: Options): string;
|
||||
7
types/viz.js/index.d.ts
vendored
Normal file
7
types/viz.js/index.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
// Type definitions for viz.js 2.1
|
||||
// Project: https://github.com/mdaines/viz.js
|
||||
// Definitions by: McKay Salisbury <https://github.com/mckaysalisbury>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="common.d.ts" />
|
||||
export = Viz;
|
||||
23
types/viz.js/tsconfig.json
Normal file
23
types/viz.js/tsconfig.json
Normal 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",
|
||||
"viz.js-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/viz.js/tslint.json
Normal file
1
types/viz.js/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
28
types/viz.js/viz.js-tests.ts
Normal file
28
types/viz.js/viz.js-tests.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import Viz = require('viz.js');
|
||||
import { Module, render } from 'viz.js/full.render.js';
|
||||
|
||||
// Correct usage
|
||||
const viz = new Viz({ Module, render });
|
||||
let promise: Promise<string>;
|
||||
promise = viz.renderString("graph a { b }", { format: "svg" });
|
||||
promise = viz.renderString("digraph a { b }");
|
||||
|
||||
// This won't necessarily work, but shouldn't violate typing rules
|
||||
new Viz({Module, render: (instance: Module, src: string, options: Options) => "string"});
|
||||
new Viz({Module, render: (instance: Module, src: string, options: {format?: string}) => "string"});
|
||||
new Viz({Module, render: (instance: Module, src: string, options: {format?: string, garbage?: number}) => "string"});
|
||||
viz.renderString("string", {files: []});
|
||||
viz.renderString("string", {images: ["totally a file"]});
|
||||
viz.renderString("string", {format: "svg", engine: "fdp", files: ["test"], images: ["totally an image"], yInvert: false});
|
||||
|
||||
// Incorrect
|
||||
new Viz({Module: 1, render}); // $ExpectError
|
||||
new Viz({Module: {}, render}); // $ExpectError
|
||||
new Viz({Module, render: (instance: Module, src: string, options: Options) => 1}); // $ExpectError
|
||||
new Viz({Module, render: (instance: string, src: string, options: Options) => "hello"}); // $ExpectError
|
||||
new Viz({Module, render: (instance: Module, src: number, options: Options) => "string"}); // $ExpectError
|
||||
new Viz({Module, render: (instance: Module, src: string, options: {format: string}) => "string"}); // $ExpectError
|
||||
viz.renderString(1, {}); // $ExpectError
|
||||
viz.renderString("string", { a: 1 }); // $ExpectError
|
||||
viz.renderString("string", { yInvert: "true" }); // $ExpectError
|
||||
viz.renderString("string", { engine: 1}); // $ExpectError
|
||||
Loading…
Reference in New Issue
Block a user