Reactjs 扩展React.Component警告
当我扩展React.Component时,如下所示:Reactjs 扩展React.Component警告,reactjs,typescript,Reactjs,Typescript,当我扩展React.Component时,如下所示: export default class App extends React.Component<any, any > { constructor (props: React.ReactPropTypes) { super(props); } // other code } 导出默认类App扩展React.Component{ 构造函数(props:React.ReactPropTypes){
export default class App extends React.Component<any, any > {
constructor (props: React.ReactPropTypes) {
super(props);
}
// other code
}
导出默认类App扩展React.Component{
构造函数(props:React.ReactPropTypes){
超级(道具);
}
//其他代码
}
我收到了以下警告:
./src/App.tsx[37,50]:“any”的类型声明将失去类型安全性。
考虑用更精确的类型替换它,空类型({{}),
或者抑制这种情况。[37,55]:任何损失的类型声明
类型安全。考虑用更精确的类型替换它,空的
键入(“{}”),或抑制此事件
解决这些警告的最佳方法是什么 在yout tslint.json中,您可以放置:
{"rules": {
"no-any": false
}
}
如果组件实际上不需要任何道具和状态,请尝试使用
{}
。如果组件确实需要来自其props/state的内容,请在类型签名中表示。