Skip to content

Inconsistents with ClientRect definition #11085

Description

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

Activity

  1. added this to the milestone on Dec 16, 2016
  2. mhegazy commented on Dec 16, 2016

    @mhegazy
    Contributor

    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.

  3. thitemple commented on Feb 3, 2017

    @thitemple

    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?

  4. muj-beg commented on Sep 27, 2017

    @muj-beg
  5. hackhat commented on Sep 11, 2018

    @hackhat

    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?

  6. HolgerJeromin commented on Sep 12, 2018

    @HolgerJeromin
    ContributorAuthor

    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
    
  7. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions