如何在typescript和antd中使用Form.create和函数组件

问题描述 投票:2回答:1

我有一个由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;

我该如何解决这个错误。

reactjs typescript antd
1个回答
3
投票

我认为这是Ant Design中TypeScript定义的一个错误: 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"),直到部署修复程序。

© www.soinside.com 2019 - 2024. All rights reserved.