我是打字新手.我显示这个有问题.状态渲染方法中的某个内容,或将其指定给函数中的某个变量.
看看最重要的一段代码:
interface State {
playOrPause?: string;
}
class Player extends React.Component {
constructor() {
super();
this.state = {
playOrPause: 'Play'
};
}
render() {
return(
<div>
<button
ref={playPause => this.playPause = playPause}
title={this.state.playOrPause} // in this line I get an error
>
Play
</button>
</div>
);
}
}
The errors says: "[ts] Property 'playOrPause' does not exist on type 'ReadOnly<{}>'.
我试图将playOrPause属性声明为一种字符串类型,但没有成功.