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

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

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

VS 2015 / TS 1.6 now gives me an error TS2339 code: "The disabled property does not exist in the HTMLElement type.

Wow! "disabled" is a property of the DOM, and it once did something in my code, and now it is no longer defined? Where did it go, and how can I handle it?

I carefully read the "What's New" notes in TS version 1.4 to 1.6, but there is nothing to say about it.

+4
source share
2 answers

Accordingly to the MDN topic , a class HTMLElementdoes not have a property such as disabled. That's why the Typescript development team is fixing this web API object.

+4
source

The interface HTMLElementdoes not contain a property disabled, because it is not a property that matters for all HTML elements. However, these are children HTMLInputElement, HTMLButtonElementetc., because the property disabledmakes sense with them.

With this in mind, you can easily fix your code.

+5
source

Source: https://habr.com/ru/post/1608480/


All Articles