I have a custom event handler function as follows
/** Dispatch event on click outside of node */
export function eventHandlers(node: HTMLElement) {
const handleClick = (event: MouseEvent) => {
if (node && !node.contains(event.target as Node)) {
node.dispatchEvent(
new CustomEvent('click_outside')
)
}
};
document.addEventListener('click', handleClick, true);
return {
destroy() {
document.removeEventListener('click', handleClick, true);
}
}
}
When I tried to use it in the HTML (svelte) as follows it throws an error:
Argument of type
{ class: string; "on:click_outside": (event: MouseEvent) => void; }
is not assignable to parameter of typeOmit<Omit<HTMLLiAttributes, "pattern" | "style" | "title" | "cite" | "data" | "form" | "label" | "slot" | "span" | "summary" | "id" | "class" | "accesskey" | ...
300 more
The html is as follows (svelte)
function handleClickOutside(event) {
alert('Click outside!');
}
<h1>Hello {name}!</h1>
<div use:clickOutside on:click_outside={handleClickOutside}>
Click outside me!
</div>
What does this mean and how can i resolve this?