忽略Typescript错误“属性在类型的值上不存在” [英] Ignore Typescript Errors "property does not exist on value of type"

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

问题描述

在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 with 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();

抛出属性'getBBox'在类型'HTMLElement'的值上不存在'。



最简单的方法是将变量显式键入 any

var outerHtmlElement: any = outerElement[0];
var coordinates = outerHtmlElement.getBBox();



编辑,2016年末



自TypeScript以来1.6首选投射算子这些线可以被抛成优雅:

Edit, late 2016

Since TypeScript 1.6 prefered casting operator is as those lines can be squqshed into elegant:

让坐标=(outerElement [0] as).getBBox();

当然,如果你想做得对,有时候有点矫枉过正,你可以:

Of course if you'd like to do it right, which is an overkill sometimes, you can:


  1. 创建自己的界面,只需扩展 HTMLElement

  2. 引入自己的输入,扩展 HTMLElement

  1. Create own interface which simply extends HTMLElement
  2. Introduce own typing which extends HTMLElement

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

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