Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
171
rated 0 times [  178] [ 7]  / answers: 1 / hits: 7458  / 4 Years ago, wed, september 30, 2020, 12:00:00

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


More From » typescript

 Answers
3

Ok, so existing answers did work only partly for me. Given that the clickOutside action fires a custom event named click_outside i arrive at following solution:


declare namespace svelte.JSX {
interface HTMLProps<T> {
onclick_outside?: (e: CustomEvent) => void;
}
}

[#2581] Thursday, September 24, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
whitney

Total Points: 642
Total Questions: 110
Total Answers: 98

Location: Solomon Islands
Member since Mon, Jun 20, 2022
2 Years ago
;