SVGElement类型上不存在属性getBBox [英] Property getBBox does not exist on type SVGElement

查看:468
本文介绍了SVGElement类型上不存在属性getBBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用d3,我想使用SVG元素具有的getBBox方法.

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

我使用的是以下内容:(d3Selection.node() as SVGElement).getBBox(),但是由于标题错误,TypeScript无法编译.

I'm using the following: (d3Selection.node() as SVGElement).getBBox(), however the TypeScript fails to compile due to the error in the title.

SVGElement使用的类型错误吗?我可以改用any来工作,但这似乎有点不干净"的解决方案.

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

推荐答案

不是所有的SVG元素都有边界框,例如<defs>没有边界框,<title>也没有边界框,所以SVGElement是错误的类型.您需要 SVGGraphicsElement

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 SVGGraphicsElement

这篇关于SVGElement类型上不存在属性getBBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆