question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Broken type for nodeTypes

See original GitHub issue

Describe the Bug

I’m now getting this type error after updating to @types/react v18:

error TS2322: Type '(props: NodeProps<any>) => Element' is not assignable to type 'ReactNode'.

38 const NodeTypes: NodeTypes = { ComponentNode: ComponentNodeContainer };
                                                 ~~~~~~~~~~~~~~~~~~~~~~

and typescript seems to be right, the definition is:

// was also called "NodeTypesType"
export declare type NodeTypes = {
    [key: string]: ReactNode;
};

So typescript is right about the incompatibility, though I don’t understand why it started only now with @types/react 18

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

just take this example:

const CustomDefaultNode: FC = () => {
    return <div>hello I'm default node</div>;
};

const initialNodes: Node[] = [
    {
        id: "node-1",
        type: "textUpdater",
        position: { x: 0, y: 0 },
        data: { value: 123 },
    },
    {
        id: "node-2",
        type: "output",
        targetPosition: Position.Top,
        position: { x: 0, y: 200 },
        data: { label: "node 2" },
    },
    {
        id: "node-3",
        type: "output",
        targetPosition: Position.Top,
        position: { x: 200, y: 200 },
        data: { label: "node 3" },
    },
];

const initialEdges = [
    { id: "edge-1", source: "node-1", target: "node-2", sourceHandle: "a" },
    { id: "edge-1", source: "node-1", target: "node-3", sourceHandle: "b" },
];

const nodeTypes = {
    output: CustomDefaultNode, // <-- would stop error when using `<CustomDefaultNode/>`
};

function App() {
    return (
        <div className="App" style={{ width: 500, height: 500 }}>
            <ReactFlow
                nodeTypes={nodeTypes} // <--- type error here
                nodes={initialNodes}
                edges={initialEdges}
            />
        </div>
    );
}

Expected behavior

The correct type should be ElementType<RelevantProps> or ComponentType<RelevantProps>.

Screenshots or Videos

No response

Platform

  • OS: MacOS
  • Browser: Chrome
  • Version: 100

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
moklickcommented, May 3, 2022

release v10.2.0 supports React18

0reactions
KutnerUricommented, May 9, 2022

cheers please make sure that you are using PropsWithChildren where relevant 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

@types/node - npm
This package contains type definitions for Node.js (https://nodejs.org/). Details. Files were exported from https://github.com/DefinitelyTyped/ ...
Read more >
Broken - TestMace
There is no tab for a Broken node to be opened in, and it can't have any child nodes. The main purpose of...
Read more >
Missing or broken '@types/node' dependency #1538 - GitHub
After adding the @google-cloud/pubsub module to my project, I got tsc compile errors: node_modules/@google-cloud/pubsub/node_modules/@grpc/grpc- ...
Read more >
How to fix broken Typescript definitions when definitions files ...
I have a project that uses Typescript, using the newer @types/foo style of installing typings packages. When my build server installs all npm...
Read more >
Node Types and States - BayesiaLab
The breaks in the outline symbolize the fact that Continuous nodes have to be discretized, i.e., broken into bins. Node Status. Regardless of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found