React TypeScript 报错类型"Readonly<{}>“上不存在属性"字段名”
react
项目中ts
报错代码如下:
onAddTabBar = () => {
let _panes = this.state.panes.concat([{ title: `Tab ${this.state.panes.length + 1}`, content: 'Content of Tab 2', key: this.state.panes.length + 1 }])
this.setState({
panes: _panes
})
console.log('==click tabBar', _panes)
};
错误提示如下:
在类声明的时候加入<any, any>
, 将props
和state
类型定义成any
就可以了如下:
如有问题请联系我~
欢迎加入QQ群: