【问题标题】:Parameter implicitly has any type in RN typescript参数在 RN typescript 中隐式具有任何类型
【发布时间】:2019-11-21 21:45:11
【问题描述】:

我的 RN 应用程序中有以下代码。

handleTextChange = e => {
  this.setState({ value: e })
}

我使用 TS,这表示“参数 'e' 隐含地具有 'any' 类型”。

我该如何解决这个问题?如何在此处将类型设置为“e”?

【问题讨论】:

  • 你期待什么样的参数?将其更改为您期望的类型
  • 检查react-native typescript definitiononChangeText 回调为TextInput,它将参数定义为string 类型。在您的情况下,如果您将 e 更改为 (e: string) 它应该修复警告。

标签: javascript node.js reactjs typescript react-native


【解决方案1】:

您可以为e 提供类型注释以防无法推断:

handleTextChange = (e: Event) => {
  this.setState({ value: e })
}

出于示例的目的,我使用了Event,但您可以使用任何合适的类型。

【讨论】:

    猜你喜欢
    • 2022-01-07
    • 2018-05-30
    • 2021-06-09
    • 2021-07-20
    • 2020-02-20
    • 1970-01-01
    • 2023-03-08
    • 2020-02-02
    • 2021-03-29
    相关资源
    最近更新 更多