Closed hellowuxin closed 3 years ago
An index.d.ts shouldn't be in the way, and would be a welcome addition to this library.
Indeed, types don't require any rewrite.
This is incomplete but might be a starting point for others. I place it in myproject/src/global.d.ts
:
declare module 'd3-flextree' {
import * as d3 from 'd3'
export function flextree<Datum>(opts: {
nodeSize?: (node: d3.HierarchyPointNode<Datum>) => [number, number]
spacing?:
| number
| ((
nodeA: d3.HierarchyPointNode<Datum>,
nodeB: d3.HierarchyPointNode<Datum>,
) => number)
}): d3.TreeLayout<Datum>
}
Just wanted to mention that I've integrated the d3-flextree layout logic into my TypeScript tree-grapher package.
Specifically, the "Core" folder in my repo corresponds to the contents of the d3-flextree package: https://github.com/Venryx/tree-grapher/tree/333cc20488e709219d72b5651ac2acb0423e6e1f/Source/Core
If all you want is the TS types (ie. .d.ts
files), you can see here: https://github.com/Venryx/tree-grapher/tree/333cc20488e709219d72b5651ac2acb0423e6e1f/Dist/Core
However, note that the types are not 100% identical to those that would be used by d3-flextree. For example, the FlexNode
class is declared within a function in d3-flextree, whereas it is a top-level, independent class in my version.
Anyway, my TypeScript version is like 95% the same API as d3-flextree, so I figured I would mention it, in case it's helpful for someone wanting to create an index.d.ts
file for d3-flextree
.
The library is made in and for JavaScript, and is currently 98.5% JavaScript. This is like opening an issue with a Java library and say "support Kotlin please?" Perhaps fork the repo and add TS support yourself? Or make your own types repo for this lib?