Cal Cal - 7 months ago 41
TypeScript Question

Property getBBox does not exist on type SVGElement

I'm using d3, and I'd like to use the getBBox method that SVG elements have.

I'm using the following:

(d3Selection.node() as SVGElement).getBBox()
, however the TypeScript fails to compile due to the error in the title.

Is SVGElement the wrong type to use? I can it working using
instead, but this seems like a bit of an "unclean" solution.

Answer Source

Not all SVG elements have bounding boxes, <defs> for instance doesn't, neither does <title>, so yes SVGElement is the wrong type to use. You want SVGLocatable

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download