我收到Property 'checked' does not exist on type 'Switch'.
来自TypeScript
forthis.checked
和this.disabled
createRefs 的消息。此外,在最后一行,我也收到了Property 'checked' does not exist on type 'Switch
来自TS
. 如何修复这些警告?
interface Props {
checked: boolean;
onChange: (checked: boolean) => void;
disabled?: boolean;
}
interface States {
checked: boolean;
disabled?: boolean;
}
export default class Switch extends React.PureComponent<Props, States> {
constructor(props: any) {
super(props);
this.checked = React.createRef(); // comment this line out to use as controlled component
this.disabled = React.createRef(); // comment this line out to use as controlled component
this.state = {
checked: false,
disabled: false,
};
}
render() {
...
<div ref={this.checked}> // TypeScript warns: Property 'checked' does not exist on type 'Switch'