我正在尝试在基于 Typescript 的项目中使用名为 redux-form 的库。当我采用他们的“简单形式”示例代码并实现它时,我得到一个错误:
error TS2604: JSX element type 'SimpleForm' does not have any construct or call signatures.
我究竟做错了什么?我已经安装了这个库的定义文件,所以要么我编码不正确,要么定义文件不正确。
在我的表单组件中(剥离代码以使其尽可能精简):
import * as React from 'react';
import {reduxForm} from 'redux-form';
export const fields = ['firstName'];
class SimpleForm extends React.Component<any, any> {
static propTypes = {
fields: React.PropTypes.object.isRequired,
};
render() {
const {
fields: {firstName}
} = this.props;
return (<form>
<div>
<label>First Name</label>
<div>
<input type="text" placeholder="First Name" {...firstName}/>
</div>
</div>
<div>
<button>
Submit
</button>
</div>
</form>
);
}
}
export default reduxForm({
form: 'simple',
fields
})(SimpleForm);
我在这里使用它(导致上述错误):
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import * as SimpleForm from '../components/GuestForm';
export default class Main extends React.Component<any, any> {
render() {
return (
<div className='mainApp'>
<SimpleForm />
</div>
);
}
}