Let's say i have a HTML element as following:
<progress value="1" max="10" id="site_progress"></progress>
VSCode shows a problem ('Property "max" does not exist on type "Element"'), if i select this element like this:
const progress = document.querySelector('#site_progress');
progress.max = 9;
There will be no problems, if i select via element selector:
const progress = document.querySelector('progress');
progress.max = 9;
Can i do something like type assertion to avoid this kind of behavior or what are good practises to handle this problem in regular javascript?
getElementByIdprogressthen the result isHTMLProgressElement | null. This will work for every other element too.div=>HTMLDivElement,input=>HTMLInputElement, etc... But if you add any other selector to it, it cannot do it.input#iddoesn't tell TS, that the selected element is aHTMLProgessElementas far as i tested.