Typescript: Cannot get obj.getBoundingClientRect().x

Created on 27 Oct 2018  路  4Comments  路  Source: microsoft/TypeScript

getDimension: (obj: HTMLElement) => {
// ...
const clientRect = obj.getBoundingClientRect();
        console.log(clientRect.x);
}
// TS2339: Property 'x' does not exist on type 'DOMRect | ClientRect'.
  Property 'x' does not exist on type 'ClientRect'.

"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"module": "commonjs",
"target": "es5",
"jsx": "react",
"locale": "ru",
"diagnostics": true
}

Most helpful comment

https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

Due to compatibility problems (see below), it is safest to rely on only properties left, top, right, and bottom.

I think that's why.

Unless you're codegolfing TypeScript or other exotic tasks, I see no reason to use x/y instead of left/top.

All 4 comments

It should probably support x and y but you can use left and top in the meantime.

https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

Due to compatibility problems (see below), it is safest to rely on only properties left, top, right, and bottom.

I think that's why.

Unless you're codegolfing TypeScript or other exotic tasks, I see no reason to use x/y instead of left/top.

Got it, thanks

use "top" instead of "y" and "left" instead of "x" I think the "top" has more Availablity in most of the browser, chrome support "y" and "top" but others maybe are not. this why the "top" is most supported cross-browser than "y"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wmaurer picture wmaurer  路  3Comments

blendsdk picture blendsdk  路  3Comments

manekinekko picture manekinekko  路  3Comments

jbondc picture jbondc  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments