我有一个由 Form.create() 创建的登录表单,但是我不能从父组件向这个表单传递任何道具,编译器总是通知一个错误,比如
error TS2339: Property 'loading' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Compone
nt<{}, ComponentState>> & Readonly<{ childr...'.
登录表单.tsx
import * as React from 'react';
import { Form } from 'antd';
import { WrappedFormUtils } from 'antd/lib/form/Form';
interface Props {
form: WrappedFormUtils;
loading: boolean;
username?: string;
}
class LoginForm extends React.Component<Props, {}> {
render() {
const { loading } = this.props;
return (<div>form {loading ? 'true' : 'false'}</div>);
}
}
export default Form.create()(LoginForm);
登录页面.tsx
import LoginForm from './components/loginForm';
const loginPage: React.SFC<Props> = (props) => {
return (
<div>
<LoginForm loading={true}/>
^ error here!
</div>
);
};
我的antd版本是2.11.2
最后我找到了解决方案
class LoginForm extends React.Component<Props & {form: WrappedFormUtils}, State> {
render() {
const { loading } = this.props;
return (<div>form {loading ? 'true' : 'false'}</div>);
}
}
export default Form.create<Props>()(LoginForm);