From aaeb6dc4b805147cb689b747c5f5b092a87b7e15 Mon Sep 17 00:00:00 2001 From: braks <78412429+bcakmakoglu@users.noreply.github.com> Date: Sun, 9 Apr 2023 21:56:40 +0200 Subject: [PATCH] fix(core): add missing `Type` generic to edge types Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com> --- packages/core/src/types/edge.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/core/src/types/edge.ts b/packages/core/src/types/edge.ts index e989f006..42b05bb5 100644 --- a/packages/core/src/types/edge.ts +++ b/packages/core/src/types/edge.ts @@ -1,7 +1,7 @@ import type { CSSProperties, Component, VNode } from 'vue' import type { ClassFunc, ElementData, Position, StyleFunc, Styles } from './flow' import type { GraphNode } from './node' -import type { DefaultEdgeTypes, EdgeComponent, EdgeTextProps } from './components' +import type { EdgeComponent, EdgeTextProps } from './components' import type { CustomEvent, EdgeEventsHandler, EdgeEventsOn } from './hooks' /** Edge markers */ @@ -58,14 +58,17 @@ export interface EdgeLabelOptions { labelBgBorderRadius?: number } -export interface DefaultEdge = any> - extends EdgeLabelOptions { +export interface DefaultEdge< + Data = ElementData, + CustomEvents extends Record = any, + Type extends string = string, +> extends EdgeLabelOptions { /** Unique edge id */ id: string /** An edge label */ label?: string | VNode | Component /** Edge type, can be a default type or a custom type */ - type?: keyof DefaultEdgeTypes | string + type?: Type /** Source node id */ source: string /** Target node id */ @@ -132,8 +135,8 @@ export type BezierEdgeType = any> = - | DefaultEdge +export type Edge = any, Type extends string = string> = + | DefaultEdge | SmoothStepEdgeType | BezierEdgeType @@ -217,3 +220,9 @@ export type SmoothStepEdgeProps = EdgePositions & Omit & Pick & SmoothStepPathOptions + +export type ToGraphEdge = GraphEdge< + T extends Edge ? Data : never, + T extends Edge ? CustomEvents : never, + T extends Edge ? Type : never +>