Unresolved variables and functions

I've been chasing my tail for some time trying to resolve some “unresolved” issues. I have an Express app and am using Nunjucks for a view engine. In a view file, I have some html inputs, and some javascript working with the dom elements, and Webstorm isn't following.

I have tried renaming the file with an ".html' extension thinking Webstorm was struggling with Nunjucks, didn't work. As a matter of fact, Webstorm had the same issue with whatever extension I tried.

 

0

You will get similar errors if you try to compile your code: “TS2339: Property 'value' does not exist on type 'Element'.” The reason is that the exact type of Element returned by document.querySelector() is unknown when analyzing code statically, so the type is inferred as generic Element. Element interface doesn't have value and focus properties. You need to explicitly tell the IDE the type of the HTMLElement which is your target using type annotations.

 

1

Thanks for the quick response.

That resolved focus but value is still complaining.

0

The HTMLElement interface has no "value" property in it, so you get those errors. You need to cast your variable to the type that has this property. For example, the HTMLInputElement interface extends HTMLElement and has a "value" property.

1

Well how about that! lol

I knew this was going to be the fix but didn't know what type to use. Is there a JSDOC cheat sheet somewhere that has a list of all the object types? I'm finding JSDOC “how to's” everywhere, but nobody lists all the possible types.

0

The MDN Web doc seems to be a better source here.

0

Not exactly what I meant but it did quickly get me to this link which I believe is what you are trying to teach me. So if I understand you correctly, all of the “HTML DOM API Interfaces” listed here can be used as types with JSDOC.

I've been struggling with JSDOC and you just added much clarity. Thank you very much!

0
You are very welcome:)
1

请先登录再写评论。