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. 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();
}
...
}
CodePudding user response:
this.scrollDiv
You are accessing the class property with this line.
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();
}
...
}