Broken type for nodeTypes
See original GitHub issueDescribe 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:
- Created a year ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
release v10.2.0 supports React18
cheers please make sure that you are using
PropsWithChildren
where relevant 😃