I
I
ivankirshin2020-01-16 11:43:04
typescript
ivankirshin, 2020-01-16 11:43:04

What type should you choose?

I don't know if the question is more about react or ts.
As I understand it, target in this case is a wider type and needs to be narrowed down to ensure that the element has a dataset.
What is the best way to do this?
Element click event handler method
Error:(47, 80) TS2339: Property 'dataset' does not exist on type 'EventTarget'.
5e202199447cd101968640.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
twolegs, 2020-01-16
@twolegs

Use generic for MouseEventHandler:
Where T is the type you want, including the dataset

R
Roman Alexandrovich, 2020-01-16
@RomReed

you can try like this
(e:MouseEvent<{dataset:string}>)=>{

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question