Typescript: Inconsistents with ClientRect definition

Created on 23 Sep 2016  路  5Comments  路  Source: microsoft/TypeScript

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

Bug lib.d.ts help wanted

Most helpful comment

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

All 5 comments

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?

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
Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanielRosenwasser picture DanielRosenwasser  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

Roam-Cooper picture Roam-Cooper  路  3Comments

manekinekko picture manekinekko  路  3Comments