Does TypeScript have type definitions for InputEvent?

Is there any node @types/* module or anything that can provide type definition for InputEvent?

  • You can install it from @types/dom-inputevent.
  • It is not in the default dom.d.ts right now cause its not widely supported / finalized as mentioned here : https://developer.mozilla.org/en-US/docs/Web/API/InputEvent

InputEvent is poorly defined in @types/dom-inputevent. As noted by others, this is because it's experimental at the time of this posting.

Instead, consider using KeyboardEvent:

inputElement.addEventListener('keyup', (e: KeyboardEvent) => 
    const input = (event.target as HTMLInputElement).value
    console.log(input, e.key)
)

Is there any node @types/* module or anything that can provide type definition for InputEvent?

Yes, there is @types/dom-inputevent which you can use for this.

Tags:

Typescript