Does TypeScript have type definitions for InputEvent?

旧街凉风 提交于 2019-12-01 14:39:02

问题


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

Read here for more info on InputEvent.


回答1:


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



回答2:


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.




回答3:


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)
)


来源:https://stackoverflow.com/questions/49714315/does-typescript-have-type-definitions-for-inputevent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!