Reactjs TS2339:不动产';宽度';不存在于类型';HTMLdevelment';

Reactjs TS2339:不动产';宽度';不存在于类型';HTMLdevelment';,reactjs,typescript,Reactjs,Typescript,我该怎么办 this.container = document.getElementById(obj.id) as HTMLDivElement; this.containerWidth =this.container.width; this.containerHeight = this.container.height 您可以使用offsetWidth: 及 您看到此错误是因为没有属性宽度。请尝试使用this.container.style.width和this.contain

我该怎么办

 this.container = document.getElementById(obj.id) as HTMLDivElement;   
 this.containerWidth =this.container.width;
 this.containerHeight = this.container.height


您可以使用
offsetWidth
: 及


您看到此错误是因为没有属性宽度。

请尝试使用this.container.style.width和this.container.style.heightThank,这解决了我的问题,但我不明白为什么。我链接了一个关于Htmlement的文档。您可以阅读文档了解更多详细信息
this.containerWidth =this.container.offsetWidth;
this.containerHeight = this.container.offsetHeight