我在使用 shouldComponentUpdate
的 TypeScript 中遇到错误:
Property 'shouldComponentUpdate' in type 'Hello' is not assignable to the same property in base type
Component<IProps, any, any>
.
在组件中:
import React, { Component } from 'react'
class Hello extends Component<IProps, any> {
shouldComponentUpdate(nextProps: IProps) { // error here
console.log(nextProps, 'nextProps')
}
....// some code
}
谁能解释一下我做错了什么?
最佳答案
将 React 与 TypeScript 一起使用有点烦人,因为今天的最后一个不包含所有必需的错误描述提示。因此,您的案例中的错误可能与 shouldComponentUpdate
方法的未完成 return
调用绑定(bind)。
尝试下一步,看看会发生什么:
shouldComponentUpdate(nextProps: IProps) { // error here
console.log(nextProps, 'nextProps')
return true
}
关于javascript - 属性 'shouldComponentUpdate' 不可分配给同一属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53632966/