svelte-file-dropzone icon indicating copy to clipboard operation
svelte-file-dropzone copied to clipboard

Typescript support

Open madeleineostoja opened this issue 3 years ago • 4 comments

Thanks for the great library port! Would be really helpful to add types for typescript users as well, I imagine they could be ported pretty much straight from the react-dropzone typings here: https://github.com/react-dropzone/react-dropzone/blob/master/typings/react-dropzone.d.ts

madeleineostoja avatar Mar 06 '22 22:03 madeleineostoja

I currently don't have enough bandwidth on doing same. PRs are welcome. You can put a reference of any other third party component which provides support. Will help someone to add support.

thecodejack avatar Apr 18 '22 12:04 thecodejack

The correct Svelte way is to use SvelteKit Packaging for the whole library. The directory "Examples" should be under routes (except helper component in a different folder). The code to be exported and the main component Dropzone.svelte should be under the directory $lib.

If you use also <script lang="ts">, then SvelteKit could then export you library with .d.ts file support for the Svelte component. You Svelte component would also be compiled to a "Pure" JS Svelte component without typescript. Notice that the exported library could be used also outside from SvelteKit itself, e.g. on REPL.

Can do it by myself and push this PR, just want your approval before because it changes the repository structure completely.

Tal500 avatar Jul 30 '22 21:07 Tal500

@Tal500 feel free to look into that.

thecodejack avatar Aug 07 '22 11:08 thecodejack

@Tal500 there is pending PR which you can takeover as well

https://github.com/thecodejack/svelte-file-dropzone/pull/97

thecodejack avatar Aug 07 '22 12:08 thecodejack

So typescript support is something that's already there. If your host TypeScript project uses TypeScript, it was already infering the attributes and types for almost all of the props in the dropzone component. That said, I've enabled ts in there, and added a typing for the one prop that wasn't inferrable (as far as I can tell) which is accept.

2.0.5 should have this, and I confirmed that accept now shows up as string | string[] | undefined as opposed to any? like it was before.

arackaf avatar Apr 06 '24 23:04 arackaf

I can't find how to type the function:

async function handleFilesSelect(e: any) {
  …
}

in <Dropzone on:drop={handleFilesSelect} /> as I would get errors if I remove the any, am I missing something?

tobiasBora avatar Apr 29 '24 23:04 tobiasBora