IWI
IWI

Reputation: 1608

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

 }
...
}

screenshot of code

Upvotes: 0

Views: 116

Answers (1)

Toxnyc
Toxnyc

Reputation: 1350

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

 }
...
}

Upvotes: 1

Related Questions