I am using the following Tidy Tree example from Observable but adding TypeScript.
I am using the following interface for the generic type Datum but I am having trouble with getting passed the following error.
Type 'any[]' is missing the following properties from type 'HierarchyPointNode<NodeData>': x, y, links, data, and 13 more.ts(2740)
index.d.ts(1885, 20): The expected type comes from the return type of this signature.
Property 'source' does not exist on type 'HierarchyNode<NodeData>'.ts(2339)
interface NodeData {
name: string;
children?: NodeData[];
}
Type error occurs here.
const link = svg
.append("g")
.attr("fill", "none")
.attr("stroke", "#555")
.attr("stroke-opacity", 0.4)
.attr("stroke-width", 1.5)
.selectAll()
.data(root.links())
.join("path")
// TypeError occurs in this line
.attr("d", (d) => {
const linkGenerator = d3
// .linkHorizontal()
.linkHorizontal()
.source((d) => [d.source.y, d.source.x])
.target((d) => [d.target.y, d.target.x]);
return linkGenerator(d);
});
What should be the correct type annotation here?
Thanks
I’ve tried .linkHorizontal<d3.HierarchyLink, d3.HierarchyPointNode … but that doesn’t seem to work.