解决TS报错Property 'style' does not exist on type 'Element'

在ts中写js修改css样式时:

let dom =document.getElementByClassName("gv-chartt");

for(let i=0; i

      dom[i].style.transform ="scale(2)";

}

当使用    dom[i].style.transform ="scale(2)";时会出现TS2339:Property 'style' does not exist on type 'Element'

原因:这是typescript的类型检查导致的,需要在querySelector方法前面加个类型断言。

解决办法如下:

let dom =document.querySelectorAll(".gv-chartt") as NodeListof;

for(let i=0; i

      dom.item(i).style.transform ="scale(2)";

}

你可能感兴趣的:(解决TS报错Property 'style' does not exist on type 'Element')