I have this line of typescript:
var audio: HTMLAudioElement = document.getElementById("audioElement");
However, I get the build error:
Type HTMLElement is not assignable to type 'HTMLAudioElement'.
Is there a different way I should be retrieving the element as an HTMLAudioElement, or do I just cast it to HTMLAudioElement?
The casting sutras for typescript looks like this:
const audio = document.getElementById("audioElement") as HTMLAudioElement;
And you can either specify the type on the audio variable if you want, but typescript will pick that up automatically for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With