[英]Property '' does not exist on type '' - despite having interface
我正在尝试创建一个类组件。 我为该类创建了一个接口,但在我的scrollDiv
属性Property '' does not exist on type ''
上出现错误Property '' does not exist on type ''
。 这门课的作文遗漏了什么?
interface ChatTabI {
state: any;
scrollDiv: any;
history: any;
user: any;
}
class ChatTab extends React.Component<ChatTabI> {
// @ts-ignore
constructor(props) {
super(props);
this.state = {
text: "",
messages: [],
loading: false,
channel: null,
};
this.scrollDiv = React.createRef();
}
...
}
this.scrollDiv
您正在使用这一行访问类属性。
所以你需要做这样的事情。
interface ChatTabI {
state: any;
scrollDiv: any;
history: any;
user: any;
}
class ChatTab extends React.Component<ChatTabI> {
scrollDiv: any; // or whatever this type would be
constructor(props) {
super(props);
this.state = {
text: "",
messages: [],
loading: false,
channel: null,
};
this.scrollDiv = React.createRef();
}
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.