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

Typescript Declaration needs updating for Svelte 4

Open revers3ntropy opened this issue 2 years ago • 6 comments

svelte-check will throw an error at the moment if you try to use events with dom elements with Svelte 4, I think the typescript declaration now needs to look more like this:

declare type FileDropEvent = import('filedrop-svelte/event').FileDropEvent;
declare type FileDropSelectEvent = import('filedrop-svelte/event').FileDropSelectEvent;
declare type FileDropDragEvent = import('filedrop-svelte/event').FileDropDragEvent;
declare namespace svelteHTML {
  interface HTMLAttributes<T> {
      'on:filedrop'?: (
          event: CustomEvent<FileDropSelectEvent> & {
              target: EventTarget & T;
          }
      ) => void;
      // etc
  }
}

(svelteHTML namespace instead of 'svelte.JSX' and 'on:event' instead of 'onevent', this seems to work for me)

revers3ntropy avatar Jun 23 '23 19:06 revers3ntropy

Is this relevent to my error?

Argument of type '{ "on:filedrop": (e: CustomEvent<FileDropSelectEvent>) => void; class: string; }' is not assignable to parameter of type 'Omit<HTMLAttributes<HTMLDivElement>, never> & HTMLAttributes<any>'.
  Object literal may only specify known properties, and '"on:filedrop"' does not exist in type 'Omit<HTMLAttributes<HTMLDivElement>, never> & HTMLAttributes<any>'.ts(2345)

jrhager84 avatar Jun 29 '23 07:06 jrhager84

I have added your declaration to my global.d.ts file, and it does remove my type error. Thanks!

jrhager84 avatar Jun 29 '23 07:06 jrhager84

No problem! Hopefully someone can update it soon, if other people are having the same issue...

revers3ntropy avatar Jun 29 '23 09:06 revers3ntropy

Does this need to be changed within the package? Sorry, I haven't been following svelte lately.

chanced avatar Jun 29 '23 14:06 chanced

I'm not really sure what you mean, but I think it's just the README that needs updating..?

revers3ntropy avatar Jun 29 '23 14:06 revers3ntropy

Will do, thanks!

I wasn't sure if src/global.d.ts was interfering and causing issues.

chanced avatar Jun 29 '23 15:06 chanced