Typescript HTMLElement disabled 1.4 to 1.6 what happened (TS2339)?

不问归期 提交于 2021-02-09 02:45:17

问题


I have been working on a TypeScript project using Visual Studio 2013 and the 1.4 version of the TS language. Just now I've upgraded the Visual Studio 2015, which uses TS 1.6.

I have code that uses the "disabled" property of an HTMLElement: var e: HTMLElement = ... e.disabled = true;

VS 2015/TS 1.6 now gives me error Code TS2339: "Property 'disabled' does not exist on type 'HTMLElement'.

Whoa! 'disabled' is a DOM property, and it used to do something in my code, and now it's no longer defined? Where did it go, and how do I deal?

I've carefully read the 'What's New' notes on the TS release from 1.4 to 1.6 but it has nothing to say on this matter.


回答1:


Corresponding to MDN topics, class HTMLElement does not have property such as disabled. That is why Typescript developers team correct this Web API object




回答2:


The HTMLElement interface does not contain the disabled property, as it is not a property which has a meaning for all HTML elements. However, it's children HTMLInputElement, HTMLButtonElement etc. does, because the disabled property makes sense with them.

With this in mind, you should be able to correct your code with little trouble.



来源:https://stackoverflow.com/questions/32716877/typescript-htmlelement-disabled-1-4-to-1-6-what-happened-ts2339

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!