Q:

property of state not usable on onChange in react+ts?

I am introducing my self in react to ts from js, this is my code and onChange:
interface AddTodoState {
  text: string;
}
class AddTodo extends Component<AddTodoProps, AddTodoState> {
  state = {
    text: ''
  };

  onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    const { name, value } = e.target;
    this.setState({
      [name]: value // error here
    });
  };

the error I am getting is: 

Property 'text' is missing in type '{ [x: string]: string; }

I am coding like that because I want the onchange to be reusable for other state prop. help?

A:

In your interface, you are expecting the component's state to have just one key (named text) with value string. What you want is a key of any name with type string and a value that is also a string. This is what the error message says also. You can change your interface to:
interface AddTodoState {
    [s: string]: string;
}

