Types do not correspond with API for d3Force?
magnusart opened this issue · 1 comments
magnusart commented
I've seen in issues that I should be able to use the following code myGraph.d3Force('link').distance(link => /* your logic */)
.
However when using typescript the type signature ForceFn
does not contain distance.
Also the d3-force-3d
project is not typed as far as I could see, so I can't use that as a base without adding my own types.
The return type is ForceFn | undefined
which is an interface that looks like this:
interface ForceFn {
(alpha: number): void;
initialize?: (nodes: NodeObject[]) => void;
[key: string]: any;
}
What is the recommended way do this in Typescript?
magnusart commented
I managed to hack around it with
const l = instance.d3Force('link')! as ForceFn2 & { distance: (link: LinkObject) => number }
l.distance(() => 50)
But that is very ugly. I had to redefine ForceFn as that was not exported. Any input welcome!