类型' {儿童:元素; }'与类型' intinsicattributes&没有共同的属性。 AnimatePresenceProps' .ts(2559)
此错误刚刚开始随机发生:
但是,如果我制作一个传播道具并引入子项的包装组件,则不会出现错误:
const WorkingVersion = (props: {id?: number}) => <SimpleComponent {...props}><div>hello</div></SimpleComponent>
此问题也不会发生在用于打字稿的codesandbox上,这让我认为这是我的特定问题机器。
我尝试恢复到上一个工作版本,但它并没有解决我遇到的问题。
我应该寻找什么可能导致弹出此错误?
This error just started happening randomly:
However if I make a wrapping component that spreads props and introduces children there's no error:
const WorkingVersion = (props: {id?: number}) => <SimpleComponent {...props}><div>hello</div></SimpleComponent>
This issue also does not happen on codesandbox for typescript making me think it's a specific issue on my machine.
I tried reverting to the last working version however it somehow didn't fix the issue I was having.
What should I be looking for that could cause this error to popup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这是最近由 此 PR 在 React v18 类型上引起的错误。其他人也遇到了同样的问题,更新后一切都崩溃了,请参阅此处打开的最近问题。我的建议是降级反应类型,直到他们为此发布修补程序。另请参阅此问题
This is a recent bug caused by this PR on types of react v18. Other people are having same problems where everything breaks down after the update, see the recent issues opened here. My suggestion is to downgrade the react types until they release a hotfix for this. See also this issue
今天面临同样的问题。
对我有用的是将
node_modules\@types\react line:511
(功能组件的接口定义)从 更改为这
只是一个临时修复,以便能够同时使用框架运动。我们可能必须等到他们发布错误修复 PR。
Faced the same issue today.
What worked for me is changing
node_modules\@types\react line:511
which is the interface definition of Function Component fromto
This is just a temporary fix to be able to work with framer-motion in the meantime. We'll probably have to wait till they release the bugfix PR.
这个解决方法为我解决了这个问题。
在项目根目录下创建一个framer-motion.d.ts文件并添加以下代码片段。
This workaround fixed it for me.
Create a
framer-motion.d.ts
file on the project root directory and add the following code snippet.新版本的React 18,社区将儿童视为FC类型的默认道具。使用此代码来解决问题。
New version of React 18, the Community removed children as a default prop on the FC type. Use this code to fix the issue.
我只是遇到了这个问题,并通过包装我的
simperecomponent
在propswithChildren&lt; {...}&gt;
中解决了它的修复。
I just had this issue and fixed it by wrapping the props type declaration of my
SimpleComponent
inPropsWithChildren<{...}>
Something like this:
将具有同一名称的组件重新列为例如使用
Framer-Motion
,然后让VS代码使用该组件。如下:Redeclare the component with same name for example if using
framer-motion
, and let VS Code use that component. Like below: