Property 'value' does not exist on type EventTarget in TypeScript

后端 未结 8 1058
野趣味
野趣味 2020-11-29 17:06

So the following code is in Angular 4 and I can\'t figure out why it doesn\'t work the way as expected.

Here is a snippet of my handler:

onUpdatingSe         


        
8条回答
  •  隐瞒了意图╮
    2020-11-29 18:04

    I was looking for a solution to a similar TypeScript error with React:

    Property 'dataset' does not exist on type EventTarget in TypeScript

    I wanted to get to event.target.dataset of a clicked button element in React:

    
    

    Here is how I was able to get the dataset value to "exist" via TypeScript:

    const onClickHandler = (event: React.MouseEvent) => {
      const { name, index } = (event.target as HTMLButtonElement).dataset
      console.log({ name, index })
      // do stuff with name and index…
    }
    

提交回复
热议问题