【发布时间】:2020-07-01 13:12:48
【问题描述】:
我最近将一个有效的 JavaScript/React 项目迁移到 Typescript。无论在什么地方,在我使用 antd 组件的 React 组件中,代码都无法进行类型检查。
例如。我有以下情况:
import { Radio, Button } from 'antd';
...
<Radio.Group ...>
<Radio.Button ...>a button</Radio.Button>
</Radio.Group>
... 我收到如下类型错误:
TS2339: Property 'Group' does not exist on type 'ForwardRefExoticComponent<RadioProps & RefAttributes<unknown>>'.
TS2339: Property 'Button' does not exist on type 'ForwardRefExoticComponent<RadioProps & RefAttributes<unknown>>'
antd typesecript 部分表明该库已准备好打字稿,甚至说您不必npm i --D @types/antd。我尝试了显式安装和不显式安装@types/antd,但这似乎没有区别。
我正在使用:
- antd@4.3.3
- typescript@3.9.5
- react@16.12.0
【问题讨论】:
-
看看这个,它可能会有所帮助:codesandbox.io/s/7x2jd
标签: reactjs typescript antd