How do I handle type assertion in vanilla Javascript when using checkJs? #31590
Labels
javascript
JavaScript support issues
*question
Issue represents a question, should be posted to StackOverflow (VS Code)
I've asked the same question on StackOverflow but I'm rephrasing it here. I'm worried that the answer to "how do I do this?" will wind up being "oh crap, you can't, we didn't think of that."
compilerOptions.checkJs=true
injsconfig.json
).js
file:let el = document.querySelector("#definitelyAnImage");
el.src = "image.png";
.src
gets marked as an error -- this is becausequerySelector
returns anElement
but the.src
property is defined on the subclass HTMLImageElement.In Typescript, I gather the solution would be to use a type-assertion before accessing the subclass property, or use
as HTMLImageElement
in the initial assignment. What can I do to get rid of this error in vanilla JS?The text was updated successfully, but these errors were encountered: