[英]Add types for listener variables react-native typescript
I have a stateful class and I need to add a listener (specifically for the keyboard). 我有一个有状态的类,我需要添加一个侦听器(特别是键盘)。 In its current form, I get an error:
在当前形式下,我得到一个错误:
TS2339 property keyboardDidShowListener doesn't exist on type 'Auth'
TS2339属性keyboardDidShowListener在'Auth'类型上不存在
I would like to know where and what type of declaration I need to put in to stop the error. 我想知道我需要在哪里以及在哪种类型的声明中停止错误。
Here's part of the code, let me know if you need more. 这是代码的一部分,如果您需要更多,请告诉我。
class Auth extends Component<Props, any> {
componentDidMount() {
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this.keyboardDidShow)
}
componentWillUnmount () {
this.keyboardDidShowListener.remove()
}
.....rest of class
This would be relevant way, to do it. 这将是相关的方法。 You might want to correct typing of
keyboard event listener
to catch invalid code while linting. 您可能需要更正
keyboard event listener
类型,以在捕捉时捕获无效的代码。
class Auth extends Component<Props, any> {
public keyboardDidShowListener: any
public componentDidMount() {
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this.keyboardDidShow)
}
public componentWillUnmount () {
this.keyboardDidShowListener.remove()
}
.....rest of class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.