From 7cf6e2b42a2be98de4635655de2984b7cfc1ced1 Mon Sep 17 00:00:00 2001 From: jolo-dev Date: Sun, 23 Feb 2025 14:45:34 +0100 Subject: [PATCH] Refactor TypeScript definitions for D2 module and update response types --- d2js/js/src/index.d.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/d2js/js/src/index.d.ts b/d2js/js/src/index.d.ts index 182eb6a23..f19bbabab 100644 --- a/d2js/js/src/index.d.ts +++ b/d2js/js/src/index.d.ts @@ -1,4 +1,4 @@ -declare module "index" { +declare module "@terrastruct/d2" { interface Options { /** * @default 0 @@ -57,11 +57,6 @@ declare module "index" { options: Options; } - // Replace the properties below with the actual structure of the worker’s responses. - export interface CompileResult { - compiled: string; - } - export interface RenderResult { svg: string; } @@ -79,9 +74,13 @@ declare module "index" { | { type: "error"; error: string } | { type: "result"; - data: CompileResult | RenderResult | EncodedResult | DecodedResult; + data: string | EncodedResult | DecodedResult; }; + export interface CompileResult { + result: string; + } + export interface D2Worker { on(event: "message", listener: (data: WorkerMessage) => void): void; on(event: "error", listener: (error: Error) => void): void; @@ -95,7 +94,7 @@ declare module "index" { worker: D2Worker; currentResolve?: ( result: - | CompileResult + | string | RenderResult | EncodedResult | DecodedResult, @@ -134,14 +133,14 @@ declare module "index" { compile( input: string | CompileRequest, options?: Options, - ): Promise; + ): Promise; /** * Renders the given diagram. * @param diagram A diagram definition in string form. * @param options Optional rendering options. */ - render(diagram: string, options?: Options): Promise; + render(diagram: string, options?: Options): Promise; /** * Encodes the provided script.