Skip to content

Commit d4bc936

Browse files
authored
Merge pull request #5650 from keepmhwn/fix/path-options-type
Define strict type for EdgeProps.pathOptions
2 parents c4fdcb1 + f7cddb9 commit d4bc936

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎.changeset/grumpy-birds-refuse.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@xyflow/react': patch
3+
---
4+
5+
Infer the type of `pathOptions` in `EdgeProps` from the edge type instead of using `any`.

‎packages/react/src/types/edges.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ type StepEdge<EdgeData extends Record<string, unknown> = Record<string, unknown>
9696

9797
type StraightEdge<EdgeData extends Record<string, unknown> = Record<string, unknown>> = Edge<EdgeData, 'straight'>;
9898

99+
type InferPathOptions<E extends Edge> = E extends { pathOptions?: infer P } ? P : any;
100+
99101
export type BuiltInEdge = SmoothStepEdge | BezierEdge | StepEdge | StraightEdge;
100102

101103
export type EdgeMouseHandler<EdgeType extends Edge = Edge> = (event: ReactMouseEvent, edge: EdgeType) => void;
@@ -158,8 +160,7 @@ export type EdgeProps<EdgeType extends Edge = Edge> = Pick<
158160
targetHandleId?: string | null;
159161
markerStart?: string;
160162
markerEnd?: string;
161-
// @TODO: how can we get better types for pathOptions?
162-
pathOptions?: any;
163+
pathOptions?: InferPathOptions<EdgeType>;
163164
interactionWidth?: number;
164165
};
165166

0 commit comments

Comments
 (0)