I've encountered an issue while using the SimulationLinkDatum Type. I have created two classes, Node and Link, which implement SimulationNodeDatum and SimulationLinkDatum. However, when attempting to use SimulationLinkDatum, TypeScript displays an error stating "Property 'x' does not exist on type 'string | number | Node'." for d.source.x, d.target.x, etc.
I am aware that SimulationLinkDatum accepts number | string | <T>
for the source and target node properties, and if a number or string is used, it will be transformed into a SimulationNodeDatum. Is this a limitation we must accept, or is there a more effective way of utilizing these interfaces?
Thank you
class D3Component {
private createPathString(d: SimulationLinkDatum<Node>) {
return 'M' + d.source.x + ',' + d.source.y + 'L' + d.target.x + ',' + d.target.y;
}
}
class Node implements SimulationNodeDatum {
public x: number;
public y: number;
constructor (public id: number) {}
}
class Link implements SimulationLinkDatum<Node> {
constructor (public source: Node, public target: Node) {}
}