看起来很简单,但我不能处理这个问题我总是在控制台收到同样的消息:类型错误:类型'(event:mouseevent)=>void'不能分配给类型')=>event'。TS2322型这是我的代码://in one class//some coderender() return ( <div className={keyStyle} key={key} onClick={() => this.props.turnKey()}></div> )//in other classs//some code return ( <div className="container"> <Display /> <Keys turnKey={this.activateKey}/> </div> ); } activateKey = (event : React.MouseEvent): void =>{ console.log(event.target); }如何解决此错误? 最佳答案 你没有通过event(这是必要的)给你的this.props.turnKey。我建议您按原样通过this.props.turnKey:<div className={keyStyle} key={key} onClick={this.props.turnKey}>或许,它能解决你的问题。如果不是,那么声明PRCturnKey: () => Event而不是turnKey: (event: React.MouseEvent) => void关于reactjs - (事件:MouseEvent <元素,MouseEvent>)=>无效'不能分配给类型'()=>事件',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54537652/
10-11 07:18