[英]Property '' does not exist on type '' - despite having interface
I am trying to create a class component.我正在尝试创建一个类组件。 I made an interface for the class, but am getting the error
Property '' does not exist on type ''
on my scrollDiv
property.我为该类创建了一个接口,但在我的
scrollDiv
属性Property '' does not exist on type ''
上出现错误Property '' does not exist on type ''
。 What was missed in the composition of this class?这门课的作文遗漏了什么?
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
You are accessing the class property with this line. this.scrollDiv
您正在使用这一行访问类属性。
So you would need to do something like this.所以你需要做这样的事情。
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.