问题
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