Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make graph data generic #435

Merged
merged 13 commits into from May 1, 2023

Conversation

nathanpovo
Copy link
Contributor

Fixes #196

This pull request adds the functionality to automatically infer the data format passed to the ForceGraph component with the use of TypeScript generics so that all ForceGraph functions/properties will automatically know the node and link data format.

Copy link
Owner

@vasturiano vasturiano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR @nathanpovo. Please see just a few comments.

src/packages/react-force-graph-2d/index.d.ts Outdated Show resolved Hide resolved
src/packages/react-force-graph-2d/index.d.ts Outdated Show resolved Hide resolved
@nathanpovo nathanpovo requested a review from vasturiano May 1, 2023 19:07
@vasturiano vasturiano merged commit 0308f9d into vasturiano:master May 1, 2023
@vasturiano
Copy link
Owner

Thanks for your work in this PR with the generic types @nathanpovo! Just merged, and will publish in a moment.

@huw
Copy link

huw commented May 7, 2023

This change is causing a TypeScript bug (microsoft/TypeScript#53287) for me when compiling. It’s not this repo’s fault, but the issue was that I was previously solving this problem by augmenting the package’s types:

declare module "react-force-graph-2d" {
  interface NodeObject extends VertexAttributes {
    id: string;
    x?: number;
    y?: number;
    fx?: number;
    fy?: number;
  }

  interface LinkObject extends EdgeAttributes {
    source: NodeObject;
    target: NodeObject;
  }
}

When importing a generic type from a package and augmenting it without supplying the parameters, TypeScript crashes completely. I don’t suspect too many users will be in my boat, but if they run into this issue hopefully they find this. The solution is just to migrate to the new generic types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TypeScript] - Generic Component w/ specific Node/Link types
3 participants