allow typescript compiler to call setState on only one react state property

前端 未结 5 2078
半阙折子戏
半阙折子戏 2020-12-13 06:17

I\'m using Typescript with React for a project. The Main component gets passed state with this interface.

interface MainState {
  todos: Todo[];
  hungry: B         


        
5条回答
  •  天命终不由人
    2020-12-13 06:47

    I think that the best way to do it is to use Partial

    Declare your component in the following way

    class Main extends React.Component> {
    }
    

    Partial automatically changes all of the keys to optional.

提交回复
热议问题