Skip to content

在使用document.querySelector获取元素时,获取到的类型是Element类型,而我们需要用到 HTMLElement 的属性,就要进行类型转换(convertion)。

typescript
document.querySelector<HTMLElement>(".panel-container").offsetWidth;
document.querySelector<HTMLElement>(".panel-container").offsetWidth;