Question: Is there a way to combine the types of different HTML DOM events in Typescript?
(I know I can avoid this error by splitting my function in two different functions but I want to avoid that)
My component looks similar to this:
const TestComponent: React.FC = () => {
const handleFileChange = (e: React.DragEvent | React.SyntheticEvent) => {
const fileData = e.dataTransfer || e.target;
});
return (
<div>
<div onDrop={handleFileChange} />
<input type="file" onChange={handleFileChange} />
</div>
)};
The error I'm getting is on the e.dataTransfer inside the handleFileChange function:
Property 'dataTransfer' does not exist on type 'SyntheticEvent<Element, Event> | DragEvent<Element>'.
Property 'dataTransfer' does not exist on type 'SyntheticEvent<Element, Event>'.
I understand this error and why this is happening, but I can't find a workaround to do this with typescript, any docs reference I should be looking at?