I'm using clickOutside directive on my svelte-typescript project and I'm getting this error when I assign custom event to the related element
Type '{ class: string; onclick_outside: () => boolean; }' is not assignable to type 'HTMLProps<HTMLDivElement>'.
Property 'onclick_outside' does not exist on type 'HTMLProps<HTMLDivElement>'
here's a snippet of my code
{#if profileToolbar}
<div
transition:fly={{ y: -20, duration: 300 }}
use:clickOutside={profileToolbarContainer}
on:click_outside={() => (profileToolbar = !profileToolbar)}
class="origin-top-right absolute right-0 mt-2 w-48 rounded-md
shadow-lg z-10 shadow-md">
this is the clickOutside directive that I'm using currently https://svelte.dev/repl/0ace7a508bd843b798ae599940a91783?version=3.16.7
I'm new to typescript so I don't really know where to start with my google search, anyone knows how to tackle this issue? thanks for your help
According to the doc, you can create a .d.ts
file in your project somewhere. And put inside that file the following:
declare namespace svelte.JSX {
interface HTMLAttributes<T> {
onclick_outside: () => void
}
}
Please read the doc for more detail.
This declaration worked for me
declare namespace svelte.JSX {
interface DOMAttributes<T> {
onclick_outside?: CompositionEventHandler<T>;
}
}
Don't forget to specify the location of your custom type declarations in tsconfig.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With