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<
|
export type Node<
|
||||||
NodeData extends Record<string, unknown> = Record<string, unknown>,
|
NodeData extends Record<string, unknown> = Record<string, unknown>,
|
||||||
NodeType extends string = string
|
NodeType extends string | undefined = string | undefined
|
||||||
> = NodeBase<NodeData, NodeType> & {
|
> = NodeBase<NodeData, NodeType> & {
|
||||||
style?: CSSProperties;
|
style?: CSSProperties;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export type InternalNode<NodeType extends Node = Node> = InternalNodeBase<NodeTy
|
|||||||
*/
|
*/
|
||||||
export type Node<
|
export type Node<
|
||||||
NodeData extends Record<string, unknown> = Record<string, unknown>,
|
NodeData extends Record<string, unknown> = Record<string, unknown>,
|
||||||
NodeType extends string = string
|
NodeType extends string | undefined = string | undefined
|
||||||
> = NodeBase<NodeData, NodeType> & {
|
> = NodeBase<NodeData, NodeType> & {
|
||||||
class?: ClassValue;
|
class?: ClassValue;
|
||||||
style?: string;
|
style?: string;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { Optional } from '../utils/types';
|
|||||||
*/
|
*/
|
||||||
export type NodeBase<
|
export type NodeBase<
|
||||||
NodeData extends Record<string, unknown> = Record<string, unknown>,
|
NodeData extends Record<string, unknown> = Record<string, unknown>,
|
||||||
NodeType extends string = string
|
NodeType extends string | undefined = string | undefined
|
||||||
> = {
|
> = {
|
||||||
/** Unique id of a node. */
|
/** Unique id of a node. */
|
||||||
id: string;
|
id: string;
|
||||||
@@ -21,8 +21,6 @@ export type NodeBase<
|
|||||||
position: XYPosition;
|
position: XYPosition;
|
||||||
/** Arbitrary data passed to a node. */
|
/** Arbitrary data passed to a node. */
|
||||||
data: NodeData;
|
data: NodeData;
|
||||||
/** Type of node defined in `nodeTypes`. */
|
|
||||||
type?: NodeType;
|
|
||||||
/**
|
/**
|
||||||
* Only relevant for default, source, target nodeType. Controls source position.
|
* Only relevant for default, source, target nodeType. Controls source position.
|
||||||
* @example 'right', 'left', 'top', 'bottom'
|
* @example 'right', 'left', 'top', 'bottom'
|
||||||
@@ -79,7 +77,15 @@ export type NodeBase<
|
|||||||
width?: number;
|
width?: number;
|
||||||
height?: 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'> & {
|
export type InternalNodeBase<NodeType extends NodeBase = NodeBase> = Omit<NodeType, 'measured'> & {
|
||||||
measured: {
|
measured: {
|
||||||
|
|||||||
Reference in New Issue
Block a user