Highlighting HTMLElement in HTMLAudioElement

I have this typescript line:

var audio: HTMLAudioElement = document.getElementById("audioElement");

      

However, I am getting a build error:

Type HTMLElement is not assignable to type 'HTMLAudioElement'.

      

Is there any other way to get the element as HTMLAudioElement or just pass it to HTMLAudioElement?

+3


source to share


1 answer


The typescript sutras look like this:

var audio = <HTMLAudioElement>document.getElementById("audioElement");

      



And you can specify the type of the audio variable if you like, but typescript will pick it up for you automatically.

+6


source







All Articles