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 <sidharthv96@gmail.com>
This commit is contained in:
Alois Klink
2024-10-22 21:47:22 +09:00
parent bb97fdbd1e
commit f8746bee04
2 changed files with 8 additions and 2 deletions

View File

@@ -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> = T | Promise<T>;
type ShapeHandler = <T extends SVGGraphicsElement>(
parent: D3Selection<T>,
node: Node,

View File

@@ -94,3 +94,10 @@ export interface RenderResult {
*/
bindFunctions?: (element: Element) => void;
}
/**
* Can be converted back to `T` by awaiting/`Awaited<T>`.
*
* This is useful for function types that may be either synchronous or asynchronous.
*/
export type MaybePromise<T> = T | Promise<T>;