chanced / filedrop-svelte

File dropzone for Svelte.
MIT License
109 stars 12 forks source link

Typescript Declaration needs updating for Svelte 4 #20

Open revers3ntropy opened 1 year ago

revers3ntropy commented 1 year ago

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)

jrhager84 commented 1 year ago

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 commented 1 year ago

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

revers3ntropy commented 1 year ago

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

chanced commented 1 year ago

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

revers3ntropy commented 1 year ago

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

chanced commented 1 year ago

Will do, thanks!

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