【问题标题】:Radio.Group and Radio.Button components don't type-checkRadio.Group 和 Radio.Button 组件不进行类型检查
【发布时间】: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

【问题讨论】:

标签: reactjs typescript antd


【解决方案1】:

在我的 tsconfig.jsoncompilerOptions 中将 moduleResolution 设置为 "node" 修复了该问题。

【讨论】:

    猜你喜欢
    • 2018-05-19
    • 2019-01-19
    • 2019-07-27
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 2023-04-03
    相关资源
    最近更新 更多