忽略打字稿错误“类型的值上不存在属性"; [英] Ignore Typescript Errors "property does not exist on value of type"
问题描述
在 VS2013 中,当 tsc 以代码 1 退出时,构建会停止.在 VS2012 中情况并非如此.
In VS2013 building stops when tsc exits with code 1. This was not the case in VS2012.
如何在忽略 tsc.exe 错误的同时运行我的解决方案?
How can I run my solution while ignoring the tsc.exe error?
我收到很多属性x"不存在于y"类型的值
错误,我想在使用 javascript 函数时忽略这些错误.
I get many The property 'x' does not exist on value of type 'y'
errors, which I want to ignore when using javascript functions.
推荐答案
我知道问题已经结束,但我发现它在搜索相同的 TypeScriptException,也许其他人在搜索这个问题时遇到了这个问题.
问题在于缺少 TypeScript 类型:
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.
The problem lays in missing TypeScript typing:
var coordinates = outerElement[0].getBBox();
抛出 'HTMLElement' 类型的值不存在属性 'getBBox'.
var outerHtmlElement: any = outerElement[0];
var coordinates = outerHtmlElement.getBBox();
编辑,2016 年末
从 TypeScript 1.6 开始,首选的转换运算符是 as
,因此可以将这些行压缩为:
Edit, late 2016
Since TypeScript 1.6, the prefered casting operator is as
, so those lines can be squashed into:
让坐标 = (outerElement[0] as any).getBBox();
当然,如果您想把事情做对(有时这有点矫枉过正),您可以:
Of course if you'd like to do it right, which is an overkill sometimes, you can:
- 创建自己的接口,简单地扩展
HTMLElement
- 引入自己的类型,它扩展了
HTMLElement
这篇关于忽略打字稿错误“类型的值上不存在属性";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!