I am checking for input type of some element, fe checkbox in TS. Now I am sure that I have element that is checkbox, so this element should have property checked. But if I s
The if statement is not necessary as others have already stated. However, there are several ways how to make compiler happy:
// 1st (best variant in my opinion)
let e1: HTMLInputElement; // type of variable
e1.checked = true;
// 2nd (sometimes a good option too)
let e2 = document.getElementById('myInput');
(e2).checked = true; // "hint" the type to TypeScript
// 3rd (a hack that may come handy sometimes)
let e3 = document.getElementById('myInput');
e2['checked'] = true;