【问题标题】:Extending React.Component warnings扩展 React.Component 警告
【发布时间】:2019-03-30 03:12:25
【问题描述】:

当我像这样扩展 React.Component 时:

export default class App extends React.Component<any, any > {

    constructor (props: React.ReactPropTypes) {
        super(props);
    }

// other code
}

我收到以下警告:

./src/App.tsx [37, 50]: 'any' 的类型声明失去了类型安全性。 考虑将其替换为更精确的类型,即空类型 ('{}'), 或抑制这种情况。 [37, 55]: 'any' 的类型声明丢失 类型安全。考虑用更精确的类型替换它,空 输入 ('{}'),或禁止出现这种情况。

解决这些警告的最佳方法是什么?

【问题讨论】:

  • 尝试使用{},如果你的组件并不真正需要它的道具和状态的任何东西。如果组件确实从它的 props/state 中要求某些东西,请在类型签名中表达出来。

标签: reactjs typescript


【解决方案1】:

在你的 tslint.json 你可以放:

{"rules": {
"no-any": false
 }      
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    相关资源
    最近更新 更多