【问题标题】:TypeScript complaining that rc-tree Tree doesn't have a treeData propTypeScript 抱怨 rc-tree Tree 没有 treeData 道具
【发布时间】:2019-12-18 22:43:05
【问题描述】:

在我的反应组件中有来自react-component/tree的以下代码,

import Tree from 'rc-tree';
...
<Tree
    className="treeThingy"
    treeData={myTreeData}
/>

这行得通,但是打字稿抱怨 treeData 道具在 Tree 上不存在,如下所示,

类型“IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly'.ts(2322)

这是我的代码、rc-tree 代码还是其他什么问题?

【问题讨论】:

    标签: typescript react-component


    【解决方案1】:

    似乎更多的是@types/rc-tree 类型声明的问题,而不是库。 TreeProps 缺少 treeData 道具,但图书馆有它。

    从版本 3 开始,react-component/tree 似乎将在包本身中包含类型,而不是在 DefinitiveTyped 包上中继。

    【讨论】:

    • 看来你是对的。我刚刚将treeData?(foo: any); 添加到@types/rc-tree.d.ts 文件中,警告就消失了。我会用 rc-tree 开一张票。谢谢。
    • definitlyTyped 上有一个 PR-36494 已关闭但未完成。看起来版本 3 是一个更好的解决方案。
    猜你喜欢
    • 2018-05-18
    • 1970-01-01
    • 2017-05-20
    • 2021-12-29
    • 2017-03-02
    • 2020-08-06
    • 2021-11-28
    • 2021-11-07
    • 2015-10-28
    相关资源
    最近更新 更多