Antd React Icon 组件中的类型错误

use*_*948 13 typescript reactjs antd

在我的 React TypeScript 项目中,我已将 antd 组件从版本 5.1 升级到 5.5,现在看到编译时错误:

 Property 'rev' is missing in type '{}' but required in type 'Pick<AntdIconProps, "value" | "onChange" | "color" | "content" | "height" | "rotate" | "translate" | "width" | "start" | "hidden" | "cite" | "data" | "form" | 
"label" | ... 349 more ... | "twoToneColor">'.
    25 |   return (
    26 |     <div>
  > 27 |       <ReloadOutlined />
       |        ^^^^^^^^^^^^^^
    28 |     </div>
    29 |   );
Run Code Online (Sandbox Code Playgroud)

看来在新版本的 antd 中,Icon 组件多了一个新的必需属性,叫做“rev”。所以现在我代码中的每个地方都必须为这个道具提供一个值!我很好奇为什么会在这个特定项目中发生这种情况(其他项目当然还有 antd 示例没有这个问题)以及是否有人遇到过这个问题

    26 |     <div>
  > 27 |       <ReloadOutlined rev={undefined}/>
    28 |     </div>
Run Code Online (Sandbox Code Playgroud)

Ami*_*deh 25

更新反应类型包来解决您的问题

npm i -D @types/react@latest
npm i -D @types/react-dom@latest
Run Code Online (Sandbox Code Playgroud)


小智 2

我有同样的问题。当我将antd版本5.1.0升级到5.4.5时。@ant-design/icon 现在有“rev”道具。