I know the question is already closed but I've found it searching for same TypeScriptException, maybe some one else hit this question searching for this problem.
(我知道这个问题已经关闭但是我发现它搜索的是同一个TypeScriptException,也许有人在搜索这个问题时遇到了这个问题。)
The problem lays in missing TypeScript typing:(问题在于缺少TypeScript类型:)
var coordinates = outerElement[0].getBBox();
Throws The property 'getBBox' does not exist on value of type 'HTMLElement'.
(引发The property 'getBBox' does not exist on value of type 'HTMLElement'.
)
The easiest way is to explicitly type variable as any
(最简单的方法是明确类型为变量any
)
var outerHtmlElement: any = outerElement[0];
var coordinates = outerHtmlElement.getBBox();
Edit, late 2016(编辑,2016年末)
Since TypeScript 1.6 prefered casting operator is as
those lines can be squqshed into elegant:
(由于TypeScript 1.6首选的投射操作符as
那些线条可以被摆成优雅:)
let coordinates = (outerElement[0] as any).getBBox();
Other solutions(其他方案)
Of course if you'd like to do it right, which is an overkill sometimes, you can:
(当然,如果你想做得对,有时候有点矫枉过正,你可以:)
- Create own interface which simply extends
HTMLElement
(创建自己的界面,只需扩展HTMLElement
)
- Introduce own typing which extends
HTMLElement
(引入自己的输入,扩展HTMLElement
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…