svelte-legos icon indicating copy to clipboard operation
svelte-legos copied to clipboard

on:clickoutside gives TS error

Open 1r00t opened this issue 1 year ago • 7 comments

When I use the clickOutsideAction, typescript complains but it is working like it should.

grafik

Argument of type '{ class: string; "on:clickoutside": () => boolean; }' is not assignable to parameter of type 'Omit<Omit<HTMLAttributes<HTMLDivElement>, "data-sveltekit-keepfocus" | "data-sveltekit-noscroll" | "data-sveltekit-preload-code" | "data-sveltekit-preload-data" | ... 49 more ... | "aria-valuetext"> & EventsWithColon<...>, never> & HTMLAttributes<...>'.
  Object literal may only specify known properties, and '"on:clickoutside"' does not exist in type 'Omit<Omit<HTMLAttributes<HTMLDivElement>, "data-sveltekit-keepfocus" | "data-sveltekit-noscroll" | "data-sveltekit-preload-code" | "data-sveltekit-preload-data" | ... 49 more ... | "aria-valuetext"> & EventsWithColon<...>, never> & HTMLAttributes<...>'.ts(2345)

1r00t avatar Mar 23 '23 15:03 1r00t

I found a solution, I needed to add this to app.d.ts in my SvelteKit project:

declare global {
    ...

    namespace svelteHTML {
        interface HTMLAttributes<T> {
            "on:clickoutside"?: (e: CustomEvent<T>) => void;
        }
    }
}

see here: https://github.com/sveltejs/language-tools/blob/master/docs/preprocessors/typescript.md#im-getting-deprecation-warnings-for-sveltejsx--i-want-to-migrate-to-the-new-typings

1r00t avatar Mar 23 '23 16:03 1r00t

Ohh no, thanks for submitting this issue, will fix this, also I had a small improvement with the clickOutsideAction, as you know sometimes we need to pass a trigger element as well which is outside the container we want to close but we don't want to perform clickOutsideAction when clicked on trigger, because trigger already manages the visibility.

ankurrsinghal avatar Mar 23 '23 17:03 ankurrsinghal

We will push that update in another release!

ankurrsinghal avatar Mar 23 '23 17:03 ankurrsinghal

@ankurrsinghal done with this?

theetherGit avatar May 20 '23 11:05 theetherGit

The same error with longpress

Argument of type '{ type: "button"; "on:longpress": () => void; }' is not assignable to parameter of type 'Omit<Omit<HTMLButtonAttributes, "data-sveltekit-keepfocus" | "data-sveltekit-noscroll" | "data-sveltekit-preload-code" | "data-sveltekit-preload-data" | ... 49 more ... | "aria-valuetext"> & EventsWithColon<...>, never> & HTMLAttributes<...>'. Object literal may only specify known properties, and '"on:longpress"' does not exist in type 'Omit<Omit<HTMLButtonAttributes, "data-sveltekit-keepfocus" | "data-sveltekit-noscroll" | "data-sveltekit-preload-code" | "data-sveltekit-preload-data" | ... 49 more ... | "aria-valuetext"> & EventsWithColon<...>, never> & HTMLAttributes<...>'

levinhtin avatar Jun 05 '23 11:06 levinhtin

on:hover as well

paolodina avatar Jul 04 '23 13:07 paolodina

Still not fixed

vlrevolution avatar Oct 19 '23 13:10 vlrevolution