From d65c48d6bbdea3cad448b5037da5aa0d6e25a810 Mon Sep 17 00:00:00 2001 From: Michael Daines <1383+mdaines@users.noreply.github.com> Date: Thu, 28 Dec 2023 09:27:25 -0500 Subject: [PATCH] wip export viz type --- .github/workflows/viz-build.yml | 1 - packages/viz/test/types/not-exported.ts | 8 ++++++++ packages/viz/test/types/package.json | 4 ++-- packages/viz/test/types/top-level.ts | 14 +------------- packages/viz/test/types/viz.ts | 8 +++++++- packages/viz/types/index.d.ts | 2 ++ 6 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 packages/viz/test/types/not-exported.ts diff --git a/.github/workflows/viz-build.yml b/.github/workflows/viz-build.yml index b0ec6c88..f576c782 100644 --- a/.github/workflows/viz-build.yml +++ b/.github/workflows/viz-build.yml @@ -115,5 +115,4 @@ jobs: run: | yarn install --frozen-lockfile yarn check-types - yarn check-types-esnext working-directory: packages/viz/test/types diff --git a/packages/viz/test/types/not-exported.ts b/packages/viz/test/types/not-exported.ts new file mode 100644 index 00000000..d432369e --- /dev/null +++ b/packages/viz/test/types/not-exported.ts @@ -0,0 +1,8 @@ +// @ts-expect-error +import { Viz } from "@viz-js/viz"; + +// @ts-expect-error +import { type SuccessResult } from "@viz-js/viz"; + +// @ts-expect-error +import { type FailureResult } from "@viz-js/viz"; diff --git a/packages/viz/test/types/package.json b/packages/viz/test/types/package.json index 9028dfd4..453ea805 100644 --- a/packages/viz/test/types/package.json +++ b/packages/viz/test/types/package.json @@ -1,11 +1,11 @@ { "private": true, + "type": "module", "dependencies": { "@viz-js/viz": "link:../..", "typescript": "^5.1.3" }, "scripts": { - "check-types": "tsc --strict --lib es2015,dom --noEmit *.ts", - "check-types-esnext": "tsc --strict --lib es2015,dom --module esnext --moduleResolution bundler --noEmit *.ts" + "check-types": "tsc --strict --lib es2015,dom --module esnext --moduleResolution bundler --verbatimModuleSyntax --noEmit *.ts" } } diff --git a/packages/viz/test/types/top-level.ts b/packages/viz/test/types/top-level.ts index d1d7e530..c37918a3 100644 --- a/packages/viz/test/types/top-level.ts +++ b/packages/viz/test/types/top-level.ts @@ -1,16 +1,4 @@ -import { instance, graphvizVersion, formats, engines, type RenderOptions, type RenderResult, type RenderError } from "@viz-js/viz"; - -// @ts-expect-error -import { Viz } from "@viz-js/viz"; - -// @ts-expect-error -import { type Viz } from "@viz-js/viz"; - -// @ts-expect-error -import { type SuccessResult } from "@viz-js/viz"; - -// @ts-expect-error -import { type FailureResult } from "@viz-js/viz"; +import { instance, graphvizVersion, formats, engines, type RenderOptions, type RenderResult, type RenderError, type Viz } from "@viz-js/viz"; let version: string = graphvizVersion; diff --git a/packages/viz/test/types/viz.ts b/packages/viz/test/types/viz.ts index 95cb1ca6..f4f556f7 100644 --- a/packages/viz/test/types/viz.ts +++ b/packages/viz/test/types/viz.ts @@ -1,4 +1,8 @@ -import { instance } from "@viz-js/viz"; +import { instance, type Viz } from "@viz-js/viz"; + +function myRender(viz: Viz, src: string) { + return viz.render(src); +} instance().then(viz => { viz.render("digraph { a -> b }"); @@ -11,6 +15,8 @@ instance().then(viz => { viz.render({ edges: [{ tail: "a", head: "b" }] }); + myRender(viz, "digraph { a -> b }"); + // @ts-expect-error viz.render("digraph { a -> b }", { format: false }); diff --git a/packages/viz/types/index.d.ts b/packages/viz/types/index.d.ts index 04fc90cb..62a28ffa 100644 --- a/packages/viz/types/index.d.ts +++ b/packages/viz/types/index.d.ts @@ -18,6 +18,8 @@ declare class Viz { renderJSON(input: string | Graph, options?: RenderOptions): object } +export { type Viz } + export interface RenderOptions { format?: string engine?: string