Merge pull request #5280 from xyflow/fezproof-patch-1

Improve typing for Nodes
This commit is contained in:
Moritz Klack
2025-05-20 11:51:39 +02:00
committed by GitHub
4 changed files with 19 additions and 6 deletions
+7
View File
@@ -0,0 +1,7 @@
---
'@xyflow/react': minor
'@xyflow/svelte': minor
'@xyflow/system': minor
---
Improve typing for Nodes
+1 -1
View File
@@ -12,7 +12,7 @@ import { NodeTypes } from './general';
*/
export type Node<
NodeData extends Record<string, unknown> = Record<string, unknown>,
NodeType extends string = string
NodeType extends string | undefined = string | undefined
> = NodeBase<NodeData, NodeType> & {
style?: CSSProperties;
className?: string;
+1 -1
View File
@@ -16,7 +16,7 @@ export type InternalNode<NodeType extends Node = Node> = InternalNodeBase<NodeTy
*/
export type Node<
NodeData extends Record<string, unknown> = Record<string, unknown>,
NodeType extends string = string
NodeType extends string | undefined = string | undefined
> = NodeBase<NodeData, NodeType> & {
class?: ClassValue;
style?: string;
+10 -4
View File
@@ -10,7 +10,7 @@ import { Optional } from '../utils/types';
*/
export type NodeBase<
NodeData extends Record<string, unknown> = Record<string, unknown>,
NodeType extends string = string
NodeType extends string | undefined = string | undefined
> = {
/** Unique id of a node. */
id: string;
@@ -21,8 +21,6 @@ export type NodeBase<
position: XYPosition;
/** Arbitrary data passed to a node. */
data: NodeData;
/** Type of node defined in `nodeTypes`. */
type?: NodeType;
/**
* Only relevant for default, source, target nodeType. Controls source position.
* @example 'right', 'left', 'top', 'bottom'
@@ -79,7 +77,15 @@ export type NodeBase<
width?: number;
height?: number;
};
};
} & (undefined extends NodeType
? {
/** Type of node defined in nodeTypes */
type?: string | undefined;
}
: {
/** Type of node defined in nodeTypes */
type: NodeType;
});
export type InternalNodeBase<NodeType extends NodeBase = NodeBase> = Omit<NodeType, 'measured'> & {
measured: {