TypeScript中使用getBoundingClientRect报错Property 'x' does not exist on type 'ClientRect | DOMRect

内容参考github ts问题11085
DomRect之前叫ClientRect,后来更名了1
ts兼容了两种对象,但ClientRect没有x,y属性。所以使用getBoundingClientRect时:

let unspecifiedRect = document.body.getBoundingClientRect();
unspecifiedRect.x // fails
let domRect = document.body.getBoundingClientRect() as DOMRect;
domRect.x       // works

  1. ClientRect更名为DomRect ↩︎

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章