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

后端 未结 8 1053
野趣味
野趣味 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 17:42

    Here's another fix that works for me:

    (event.target as HTMLInputElement).value

    That should get rid of the error by letting TS know that event.target is an HTMLInputElement, which inherently has a value. Before specifying, TS likely only knew that event alone was an HTMLInputElement, thus according to TS the keyed-in target was some randomly mapped value that could be anything.

提交回复
热议问题