网站搜索

reactjs - 如何在 TypeScript 和 Antd 中用函数组件使用 Form.create


我有一个由 Form.create() 创建的表格,但我不能成功编译。

错误像:

Argument of type 'FunctionComponent<MyProps>' is not assignable to parameter of type 'ComponentType<{}>'.
  Type 'FunctionComponent<MyProps>' is not assignable to type 'FunctionComponent<{}>'.
    Type '{}' is missing the following properties from type 'MyProps': form, and 2 more

我的代码是:

import { FormComponentProps } from "antd/lib/form";

interface MyProps extends FormComponentProps {
   form: any;
}

const TableQuery: FunctionComponent<MyProps> = (props: MyProps) => {
 // some code
};

const WrappedTableQuery = Form.create<MyProps>()(TableQuery)

export default WrappedTableQuery;

我该如何修复这个错误。

答案#1

我认为这是 Ant Design 中 TypeScript 定义的一个 bug:
https://github.com/ant-design/ant-design/issues/16229(中文)
https://github.com/ant-design/ant-design/issues/16095#issuecomment-485709670(英文)

它出现在版本 3.16.4(发布于 2019-04-21),并且在版本 3.16.5 中仍然存在。
在修复部署之前,你可以使用之前的版本("antd": "3.16.3")。