xyflow / xyflow

React Flow | Svelte Flow - Powerful open source libraries for building node-based UIs with React (https://reactflow.dev) or Svelte (https://svelteflow.dev). Ready out-of-the-box and infinitely customizable.
https://xyflow.com
MIT License
21.84k stars 1.45k forks source link

`Edge` should accept a generic `type` argument like `Node` #4283

Closed kevinschaich closed 2 weeks ago

kevinschaich commented 2 weeks ago

Definition for Node:

export type Node<T = any, U extends string | undefined = string | undefined> = {
    id: string;
    data: T;
    type?: U;
    ...
}

Usage:

export type MyNode = Node<MyNodeData, 'my-node'>

Perfect. The def for Edge is inconsistent:

export type Edge<T = any> = DefaultEdge<T> | SmoothStepEdgeType<T> | BezierEdgeType<T>;

...

type DefaultEdge<T = any> = {
    id: string;
    data?: T;
    type?: string;
    ...
}

This means you can't enforce that generic props map to a discrete number of edge types throughout your app.

kevinschaich commented 2 weeks ago

Actually should mention I'm on v11 and these are the exported types I'm seeing. Maybe fixed in:

cc: @moklick ? Happy to close out if so

moklick commented 2 weeks ago

Yep, that's fixed in v12 https://github.com/xyflow/xyflow/blob/main/packages/system/src/types/edges.ts