我有一个不编译的React类型记录应用程序。许多组件都有一个类型为返回React.ReactNode或React.ReactElement的呈现方法。在编译时,报告了许多与以下类似的错误:
TS2786: 'MessagesWidget' cannot be used as a JSX component.
Its instance type 'MessagesWidget' is not a valid JSX element.
The types returned by 'render()' are incompatible between these types.
Type 'React.ReactNode' is not assignable to type 'import("/home/node/app/node_modules/@types/react-calendar/node_modules/@types/react/index").ReactNode'.为什么编译器期望由与ReactNode捆绑的类型定义的react-calendar?我确实将@types/react-dom安装为一个dev依赖项。
其他可能相关的信息:
@types/react和@types/react-dom。然而,将这些包滚回旧版本并没有解决这个问题。JSX.Element将删除编译器错误,但是应用程序中存在第三方组件,这是不可能的。发布于 2022-09-27 11:35:08
只需在package.json中添加re和re dom的最新版本,然后在下面的命令中运行,以便重新安装react和re dom。
在这里,当发布这个答案时,最新版本的是18。
步骤-
“@type/dom”:"^18",“@type/dom dom”:"^18“
4.运行命令
npm安装
好了。它解决了我的问题。
https://stackoverflow.com/questions/71831601
复制相似问题