reactjs - care este tipul props-urilor în Typescript când personalizez controlul de formular ant-design
codul componentului meu de formular aici:
import * as React from 'react';
import { From } from 'antd';
import { FormComponentProps } from 'antd/es/form';
import CustomControl from './CustomControl'
interface IProps extends FormComponentProps {
}
class MyForm extends React.Component<IProps> {
constructor(props: IProps) {
super(props);
}
public render(): React.ReactNode {
const { getFieldDecorator } = this.props.form
return <Form>
<Form.Item label="custom-control">
{
getFieldDecorator('custom-field', {initialValue: 'custome-value'})
(<CustomControl />)
}
</Form.Item>
</Form>
}
}
export default Form.create<IProps>()(MyForm);
controlul meu de formular personalizat aici:
import * as React from 'react';
import { Input } from 'antd';
const { forwardRef, useState } = React;
function CustomControl(props: any) {
const [value, setValue] = useState(props.value);
const handleChange = (value: string) => {
if (props.onChange) {
setValue(value)
props.onChange(value)
}
}
return <div>
<Input value={value} onChange=((e) => handleChange(e.currentTarget.value)) />
</div>
}
export default forwardRef(CustomControl)
este acest any:
function CustomComponent(props: any) {}
Nu pot să definesc tipul acestei proprietăți care este transmis de antd getFieldDecorator, codul din antd despre getFieldDecorator:
getFieldDecorator<T extends Object = {}>(id: keyof T, options?: GetFieldDecoratorOptions): (node: React.ReactNode) => React.ReactNode;
React.ReactNode evident nu este pentru mine.
Deci, pot să scriu aici doar any, nu este destul de prietenos.
Te rog să-mi arăți cum să optimizez acest any.