【问题标题】:Run time TypeError: input.toLowerCase is not a function运行时类型错误:input.toLowerCase 不是函数
【发布时间】:2021-10-14 09:49:37
【问题描述】:

在运行我的react app 时出现错误:TypeError: input.toLowerCase is not a function

上下文:这是一个表单,我在控制器中有一个文本字段。最初我正在处理的字段 id 是string,但我需要将其更改为number。那是类型问题开始的时候。

我认为错误来自我的这行代码:

                      inputValue={inputValue as unknown as string}

  onInputChange={(_e, newInputValue) => {
                        setInputValue(parseInt(newInputValue)); //this line
                      }}

使用parseInt 是我发现摆脱这个初始错误的方法:

Argument of type 'string' is not assignable to parameter of type 'SetStateAction<number>'.ts

有什么想法吗?

【问题讨论】:

    标签: reactjs typescript types runtime typeerror


    【解决方案1】:

    我不知道你的代码在做什么,但似乎在某个地方,可能在setInputValue,代码正在执行input.toLowerCase。由于您将string 解析为number,因此input.toLowerCase 将失败。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-05
      • 1970-01-01
      • 2016-02-26
      • 2013-04-01
      • 2016-03-06
      • 1970-01-01
      • 2018-04-28
      相关资源
      最近更新 更多