'play' does not exist on type 'HTMLElement' and Property 'value' does not exist on type 'EventTarget'

Viewed 19793

Not sure why these two warning came from. Any idea to get rid of those warning message from typescript? Thanks

error TS2339: Property 'play' does not exist on type 'HTMLElement'.

    export function playAudio(e, audioId) {
        e.preventDefault()
        let audioPlayer: HTMLElement = document.getElementById(audioId)
        audioPlayer.play();
    }

(248,82): error TS2339: Property 'value' does not exist on type 'EventTarget'.

    <input type="checkbox" id="inputSchedule" name="inputCheckboxesSchedule"
           value={this.state.displayMode}
           onClick={e => this.toogleDisplaymode(e.target.value)}/>
4 Answers

In Angular 5 you need to cast it as follows:

let audioPlayer = <HTMLVideoElement> document.getElementById(audioId);

audioPlayer.play();  

In angular 7 works this code:

let audioPlayer = <HTMLVideoElement>document.getElementById('video');
audioPlayer.muted = true;
Related