Does TypeScript have type definitions for InputEvent?

前端 未结 3 1753
感情败类
感情败类 2021-01-07 18:27

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

Read here for more info on InputEvent<

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-07 19:10

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

提交回复
热议问题