Merge pull request #5280 from xyflow/fezproof-patch-1
Improve typing for Nodes
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
---
|
||||
'@xyflow/react': minor
|
||||
'@xyflow/svelte': minor
|
||||
'@xyflow/system': minor
|
||||
---
|
||||
|
||||
Improve typing for Nodes
|
||||
@@ -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;
|
||||
|
||||
@@ -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,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: {
|
||||
|
||||
Reference in New Issue
Block a user