Hacker News new | ask | show | jobs
by mambodog 3361 days ago
I mean if you really want to be loose with the type of your component's state, you can just declare its type as Object, eg.

    class MyComponent extends React.Component {
      state: Object;

      constructor(props) {
        super(props);

        
        this.state = {
          foo: 1, // no type error
        };
      };
    }
Providing a more explicit type for the component's state is a great way to catch bugs, however. It also forces you to more clearly think through which combinations of state properties are valid. Jared Forsyth gave a good talk about this at React Conf: https://www.youtube.com/watch?v=V1po0BT7kac