【发布时间】: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