I have the _onClick function, which listens to click or touch events depending on the device, so my event is MouseEvent or TouchEvent type.
In useEffect, addEventListener complains with the message: No overload matches this call (2769).
How can I properly write this down to avoid TS error?
const _onClick = (e: MouseEvent & TouchEvent):void => {
e.preventDefault();
const positionX = (e.touches && e.touches[0].pageX) || e.clientX;
};
useEffect(() => {
if (tablet) {
document.addEventListener('touchstart', _onClick);
}
document.addEventListener('mousedown', _onClick);
}
}, []);