当我在我的代码中尝试使用this.state时,流量给我以下错误:
object literal:
This type is incompatible with
undefined. Did you forget to declare type parameterState
of identifierComponent
?:
这是违规代码(虽然它也发生在其他地方):
class ExpandingCell extends Component { constructor(props) { super(props); this.state = { isExpanded: false }; }
任何帮助将不胜感激=)
您需要在使用该属性之前定义state属性的类型。
class ComponentA extends Component { state: { isExpanded: Boolean; }; constructor(props) { super(props); this.state = { isExpanded: false }; } }