JSDoc: Property 'value' does not exist on type 'EventTarget'

I’m using vanilla JavaScript with TypeScript as pre-processor in combination with JSDoc.
That pretty much works flawlessly, especially in the backend (when using in NodeJS, for instance).

However, when I use it with DOM objects, things get a bit tricky.

For example: Say I have an HTML Input field, I catch the input event and want to access the input’s value with e.target.value:

 * Log data on input
 * @param {Event} e
let handleEvent = function(e){

document.getElementById("my-input").addEventListener("input", handleEvent);

This results in a TS warning:

Property ‘value’ does not exist on type ‘EventTarget’

As seen here:

TypeScript Warning

Now my question is, what’s the correct @param annotation?

So far I’ve tried Event, InputEvent and HTMLInputElement.

I don’t want to use Type-Assertion. Instead I’d like to know how to specify it in the functions annotations directly, so I do not have to set @type for each and every occurrence of e.target.value individually as suggested here.

39 thoughts on “JSDoc: Property 'value' does not exist on type 'EventTarget'”

  1. You could definitely see your skills within the work you write.
    The sector hopes for even more passionate writers such as you who aren’t afraid to say how they believe.

    All the time go after your heart.

  2. Pingback: keto candy

Leave a Comment