TypeScript Version: 2.0.3
Typescript 2.0.3 has a lot of readonly stuff in lib.d.ts.
I am surprised that only height and width is readonly in ClientRect definition.
interface ClientRect {
bottom: number;
readonly height: number;
left: number;
right: number;
top: number;
readonly width: number;
}
Is this an error?
Mozillas response of getBoundingClientRect is the other way round:
all but height/width readonly (if i can trust FireBug) and has added x, y
Sidenote: ClientRect has been renamed to DOMRect
PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.
I'd be willing to do this. It seems pretty straightforward. If I understand the spec correctly, there are two properties missing x and y.
X, Y, width and height should not be readonly and the others should.
Also, about the name, which is now DOMRect, should I rename it? Or should I just create a new interface and make one inherit from the other?
Pull request: https://github.com/Microsoft/TSJS-lib-generator/pull/299
getBoundingClientRect().x gives me Error:(19, 30) TS2339: Property 'x' does not exist on type 'ClientRect | DOMRect'. Property 'x' does not exist on type 'ClientRect'.
How come has not been fixed yet?
To be backward compatible getBoundingClientRect returns the old and new interface:
let unspecifiedRect = document.body.getBoundingClientRect();
unspecifiedRect.x // fails
let domRect = document.body.getBoundingClientRect() as DOMRect;
domRect.x // works
Most helpful comment
To be backward compatible getBoundingClientRect returns the old and new interface: