我已经构建了一个组件,它将根据它在窗口中的尺寸和位置来确定它的打开方向。我在 react-dom 节点上使用了 getBoundingClientRect() 函数。现在我已经更新了一些项目包,包括 react 和 react-dom 到 16.3.2。现在我得到一个编译错误:
Property 'getBoundingClientRect' does not exist on type 'Element | Text'
这是一段使用此功能的代码:
const node = ReactDOM.findDOMNode(this.containerElement);
if (!node) {
return;
}
let vertical: Vertical_Direction;
if (verticalDirection === Vertical_Direction.DOWN_UP) {
const windowHeight = window.innerHeight;
const height: number = Math.min(containerHeight, node.getBoundingClientRect().height);
任何实现此功能的帮助或建议将不胜感激。
Edit2:此问题的原因是将 @types/react-dom 更新到 16.0.5 版本。