Typescript: Property ‘src’ does not exist on type ‘HTMLElement’

Because src is not a property of the HTMLElement type, but of HTMLImageElement.

If you are certain you’ll get an img element, you might want to declare your variable with the correct subtype:

element: HTMLImageElement; /* Defining element */

// ...

this.element = document.createElement('img'); /*creating a img*/

Also, you might want to have a look at what document.createElement returns. It’s the very same type if you specify "img" as its argument.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)