Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Declaration needs updating for Svelte 4 #20

Open
revers3ntropy opened this issue Jun 23, 2023 · 6 comments
Open

Typescript Declaration needs updating for Svelte 4 #20

revers3ntropy opened this issue Jun 23, 2023 · 6 comments

Comments

@revers3ntropy
Copy link

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
Copy link

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
Copy link

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

@revers3ntropy
Copy link
Author

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

@chanced
Copy link
Owner

chanced commented Jun 29, 2023

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

@revers3ntropy
Copy link
Author

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

@chanced
Copy link
Owner

chanced commented Jun 29, 2023

Will do, thanks!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants