From f8746bee0454b01378726d04f9c65bbc3974eb3a Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Tue, 22 Oct 2024 21:47:22 +0900 Subject: [PATCH] refactor: move `MaybePromise` type to src/types.ts Suggested-by: https://github.com/mermaid-js/mermaid/pull/5974#discussion_r1810562136 Co-authored-by: Sidharth Vinod --- .../src/rendering-util/rendering-elements/shapes.ts | 3 +-- packages/mermaid/src/types.ts | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/rendering-util/rendering-elements/shapes.ts b/packages/mermaid/src/rendering-util/rendering-elements/shapes.ts index acda544e27..89beb85e01 100644 --- a/packages/mermaid/src/rendering-util/rendering-elements/shapes.ts +++ b/packages/mermaid/src/rendering-util/rendering-elements/shapes.ts @@ -1,5 +1,5 @@ import type { Entries } from 'type-fest'; -import type { D3Selection } from '../../types.js'; +import type { D3Selection, MaybePromise } from '../../types.js'; import type { Node, ShapeRenderOptions } from '../types.js'; import { anchor } from './shapes/anchor.js'; import { bowTieRect } from './shapes/bowTieRect.js'; @@ -58,7 +58,6 @@ import { waveEdgedRectangle } from './shapes/waveEdgedRectangle.js'; import { waveRectangle } from './shapes/waveRectangle.js'; import { windowPane } from './shapes/windowPane.js'; -type MaybePromise = T | Promise; type ShapeHandler = ( parent: D3Selection, node: Node, diff --git a/packages/mermaid/src/types.ts b/packages/mermaid/src/types.ts index 891071b109..8912317728 100644 --- a/packages/mermaid/src/types.ts +++ b/packages/mermaid/src/types.ts @@ -94,3 +94,10 @@ export interface RenderResult { */ bindFunctions?: (element: Element) => void; } + +/** + * Can be converted back to `T` by awaiting/`Awaited`. + * + * This is useful for function types that may be either synchronous or asynchronous. + */ +export type MaybePromise = T | Promise;