Question : Property 'style' does not exist on type 'Element'.ts(2339)
Answered by : thankful-teira-p1hq2y5zkhk7
// Cast to the type of `HTMLElement`
const el = document.getElementById('whatever') as HTMLElement;
el.style.paddingTop = ...;
// Or, if it is an array
const els = document.getElementsByClassName('my-class') as HTMLCollectionOf<HTMLElement>;
Source : https://stackoverflow.com/questions/58773652/ts2339-property-style-does-not-exist-on-type-element | Last Update : Mon, 16 Aug 21
Question : Property 'of' does not exist on type 'typeof Observable'.
Answered by : thoughtful-tuatara-dq1hh2ul7sdd
import { of } from 'rxjs';
Source : https://stackoverflow.com/questions/38067580/property-of-does-not-exist-on-type-typeof-observable | Last Update : Sat, 31 Oct 20
Question : Property 'value' does not exist on type 'HTMLElement'.
Answered by : anurag-srivastava
document.getElementById() returns the type HTMLElement which does not contain a value property.
The subtype HTMLInputElement does however contain the value property.
So a solution is to cast the result of getElementById() to HTMLInputElement like this:
var inputValue = (<HTMLInputElement>document.getElementById(elementId)).value;
<> is the casting operator in typescript.
See TypeScript: casting HTMLElement: https://fireflysemantics.medium.com/casting-htmlelement-to-htmltextareaelement-in-typescript-f047cde4b4c3
The resulting javascript from the line above looks like this:
inputValue = (document.getElementById(elementId)).value;
i.e. containing no type information.
Source : https://fireflysemantics.medium.com/casting-htmlelement-to-htmltextareaelement-in-typescript-f047cde4b4c3 | Last Update : Sat, 24 Oct 20
Question : Property 'style' does not exist on type 'Element'
Answered by : mobile-star
const node = document.querySelector<HTMLElement>(element);
Source : https://github.com/Microsoft/TypeScript/issues/16920 | Last Update : Tue, 07 Sep 21