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
}
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"
Most helpful comment
https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
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.