Ts Js input赋值报错The property 'value' does not exist on value of type 'HTMLElement'解决办法

最近做ionic项目,遇到了需要给input赋值的操作,结果报错:

Ts Js input赋值报错The property 'value' does not exist on value of type 'HTMLElement'解决办法
Ts Js input赋值报错The property 'value' does not exist on value of type 'HTMLElement'解决办法
解决办法:
Ts Js input赋值报错The property 'value' does not exist on value of type 'HTMLElement'解决办法
即:const inputContant = (document.getElementById('suggestId') as HTMLInputElement);

原因是HTMLElement返回自getElementById()实际上是HTMLInputElement从其继承的实例,因为传递的是输入元素的ID。同样,在静态类型的Js(Ts)中,它不会编译。