I need to create a custom rest hook that has the parameter Event, and this parameter should be able to receive 2 types of Events - keyboard and mouse. I was trying to use union of types like MouseEvent | KeyboardEvent and it is not working :/
Any suggestions? Example below
<input
type="text"
value={query}
onChange={e => setQuery(e.target.value)}
onKeyDown={e => getUserPosition(e, query, assetType)}
/>
<Button
fullWidth
color="secondary"
onClick={e => getUserPosition(e, query, assetType)}
>
Search
</Button>
const getUserPosition = (
e: MouseEvent & KeyboardEvent, <-- here is problem
queryuery: string,
assetType: AssetType
) => {
if (e?.key === 'Enter') {
// do something
}
if (e?.type === 'click') {
//do something
}
}