The following is my function
export function clickOutside(node: HTMLElement) {
const handleClick = (event: MouseEvent) => {
if (!node.contains(event.target as Node)) {
node.dispatchEvent(new CustomEvent('outclick'));
}
};
document.addEventListener('click', handleClick, true);
return {
destroy() {
document.removeEventListener('click', handleClick, true);
}
};
}
I use this as following
<div class="modal" use:clickOutside on:outclick={() => {showModal = false}}>
{#if showModal}
<SignIn />
{/if}
</div>
I get an error saying Argument of type '{ class: string; "on:outclick": () => void; }' is not assignable to parameter of type 'Omit<Omit<HTMLAttributes. But the code works alright. I guess it could be the typescript related error.
How can I solve this?