Skip to content

Commit

Permalink
refactor: move MaybePromise type to src/types.ts
Browse files Browse the repository at this point in the history
Suggested-by: #5974 (comment)
Co-authored-by: Sidharth Vinod <[email protected]>
  • Loading branch information
aloisklink and sidharthv96 committed Oct 22, 2024
1 parent bb97fdb commit f8746be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions packages/mermaid/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

0 comments on commit f8746be

Please sign in to comment.