Skip to content

SVGRect should not alias DOMRect in lib.dom.d.ts #974

Open
@patorpey

Description

@patorpey

In the currently generated lib types, SVGRect is equivalent to DOMRect. The initial SVG recommendation of SVGRect is as an independent interface, not associated with DOMRect. While the Geometry Interfaces Module Level 1 IDL specifies SVGRect as a legacy alias for DOMRect, the SVG WG agreed to revert merging SVG and DOM geometry interfaces in 2019, keeping SVGRect as an distinct interface. The decision was made as a result of no browser supporting the change due to implementation difficulties.

The adverse effect of this with respect to lib.dom.d.ts is that TypeScript does not produce an error when accessing properties of DOMRect that do not exist on SVGRect and, thus, will fail at runtime. Additionally, editors will suggest completions for these properties that will not exist at runtime. Properties available on DOMRect but are not implemented on SVGRect include bottom, top, left, and right inherited from DOMRectReadOnly.

Additionally, some methods on SVG interfaces return DOMRect instead of SVGRect, which is problematic when they are not aliases of the same type. For example:
SVGGraphicsElement.getBBox(options?: SVGBoundingBoxOptions): DOMRect;
Since SVGRect is not actually implemented as an alias of DOMRect, these methods should return an SVGRect for proper type-checking. This likely affects other geometry interfaces that have been aliased or declared to be DOM versions when only SVG versions are supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions