简体   繁体   中英

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. 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.

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();

 }
...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM