财产'手柄选择更改'在类型''在Ant设计表单中



Ant设计有一个用于表单的HOC包装器,其实现方式如下:

class View extends Component {
render() {
return ( <FormItem
{...formItemLayout}
label='Country'>
{getFieldDecorator('country', {
initialValue: Company && Company.country,
})(
<Select
showSearch={true}
optionFilterProp="children"
filterOption={(input: any, option: any) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
placeholder="Select a Country"
onChange={this.handleSelectChange}
>
{countrylist}
</Select>
)}
</FormItem>)
}
}
export default compose(
Form.create()
...
)(View)

在正常的javascript中,this.handleSelecChange工作得很好,但我正在尝试将我的项目迁移到typescript,我得到了:

类型View 上不存在属性"handleSelectChange">

我试着扩展接口,但我做得不对。我该如何让它发挥作用?

问题是,即使调用了Form.create((,元素也没有包装它——它在一个更高的组件中。这里不需要调用Form.create((,只需在表单组件中执行即可,然后将表单作为道具传递下去。然后你可以使用

form.handleSelectChange

这是有效的。

最新更新