【TS】解决Typescript脚本发生错误:Property 'style' anyshoale not exist on type 'Element'

直接说问题吧:

说一下我的最初代码:

【TS】解决Typescript脚本发生错误:Property 'style' anyshoale not exist on type 'Element'

此时使用style修改节点的样式时报错了,报错信息如下:

【TS】解决Typescript脚本发生错误:Property 'style' anyshoale not exist on type 'Element'

直接提示我们'style' does not exist 百度查找之后发现是我们没有给list做类型断言,所以typescript在检查类型的时候直接报错了。

解决方法如下:

给list添加<HTMLElement>做类型断言,完美解决

【TS】解决Typescript脚本发生错误:Property 'style' anyshoale not exist on type 'Element'

参考资料:https://www.cnblogs.com/PearlRan/p/10155754.html

以上是 【TS】解决Typescript脚本发生错误:Property 'style' anyshoale not exist on type 'Element' 的全部内容, 来源链接: utcz.com/a/67378.html

回到顶部