Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a "HTMLInputElement" type in TypeScript [duplicate]

There is a <input type="checkbox" id="mainCheckbox" />,I want to use the property checked of it.And the vscode waring Property 'checked' does not exist on type 'HTMLElement'.I know that must be type HTMLInputElement,But I can't change it,the method getElementById() is return the type HTMLElement;

var controlCheckbox= document.getElementById("mainCheckbox"),
    addBtn = document.getElementById("btn_add"),
    container = document.getElementById("observers");
ObserverSubject.extend(new ObserverSubject.Subject(), controlCheckbox);
controlCheckbox.onclick=()=>{
    this.Notify(controlCheckbox.checked);
}

enter image description here

like image 876
codelegant Avatar asked Nov 01 '15 08:11

codelegant


1 Answers

Try this simple cast:

var controlCheckbox = <HTMLInputElement>document.getElementById("mainCheckbox")
like image 71
Shikloshi Avatar answered Sep 17 '22 03:09

Shikloshi