I have got an object called datum which is of type HierarchyPointNode<TreeNodeDatum>
datum: HierarchyPointNode<TreeNodeDatum>
HierarchyPointNode and TreeNodeDatum are imported as follows:
import { TreeNodeDatum } from 'react-d3-tree/lib/types/common';
import { HierarchyPointNode } from 'd3-hierarchy';
I want to save datum to another object node and I need to create type definitions for this object node. May I know how do I do it?
// declare types for node
interface node{
// How to find types of datum and use the same here?
}
When I console.log(datum)
, I get this
{
"data": {
"name": "CAMPAIGN",
"attributes": {},
"children": [],
"__rd3t": {
"id": "cad115be-5f96-407d-833b-9e20377d9079",
"depth": 0,
"collapsed": false
}
},
"height": 0,
"depth": 0,
"parent": null,
"x": 0,
"y": 0
}
Interface of <TreeNodeDatum>
export interface RawNodeDatum {
name: string;
attributes?: Record<string, string | number | boolean>;
children?: RawNodeDatum[];
}
export interface TreeNodeDatum extends RawNodeDatum {
children?: TreeNodeDatum[];
__rd3t: {
id: string;
depth: number;
collapsed: boolean;
};
}
Interface of HierarchyPointNode
export interface HierarchyPointNode<Datum> extends HierarchyNode<Datum> {
/**
* The x-coordinate of the node.
*/
x: number;
/**
* The y-coordinate of the node.
*/
y: number;
/**
* Returns an array of links for this node, where each link is an object that defines source and target properties.
* The source of each link is the parent node, and the target is a child node.
*/
links(): Array<HierarchyPointLink<Datum>>;
}