uppy icon indicating copy to clipboard operation
uppy copied to clipboard

Consider adding TypeScript declarations for uppy Svelte package

Open apirogov opened this issue 4 years ago • 9 comments

It would be great to have that so svelte-check will not complain anymore and for more useful information that the TypeScript compiler can work with!

Currently I get:

Hint: Could not find a declaration file for module '@uppy/svelte'. '[...]/node_modules/@uppy/svelte/dist/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/uppy__svelte` if it exists or add a new declaration (.d.ts) file containing `declare module '@uppy/svelte';` (ts)

    import { DashboardModal } from "@uppy/svelte"

Also I get errors when instantiating uppy, e.g. let uppy = new Uppy() yields the error

[ts 2350] [E] only a void function can be called with the 'new' keyword.

apirogov avatar Aug 20 '21 13:08 apirogov

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 03 '22 02:12 stale[bot]

Nope

frederikhors avatar Dec 03 '22 09:12 frederikhors

This would be very nice to have, is there currently a temp work around for this?

Romeo-V1 avatar Jun 09 '23 07:06 Romeo-V1

This is how I can use it for now, this should do as a workaround:

<script lang="ts">
    import Dashboard from "@uppy/dashboard";
    import Uppy from '@uppy/core';
// Idk if that css import is needed
    import '@uppy/core/dist/style.css';
    import '@uppy/dashboard/dist/style.css';
	import { onMount } from "svelte";
    
    onMount(()=>{
        const uppy = new Uppy({id: "lalal", allowMultipleUploads:false,restrictions:{maxNumberOfFiles:1,maxFileSize:10000000,allowedFileTypes:[".pdf",".docx",".pptx",".html"]}});
        uppy.use(Dashboard,{inline:true, target:"#dashboard"})
    });
</script>


<main>
    <div id="dashboard"></div>
</main>

EDIT: You do need to import the css files.

Flajt avatar Jun 12 '23 15:06 Flajt

what a horrible workaround, the same issue of types happens with react

ApioSoftwareSolutions avatar Apr 22 '24 17:04 ApioSoftwareSolutions

Note that we're done with the complete transition of the codebase to TS. It will be released soon under 4.0.0

Murderlon avatar Apr 23 '24 09:04 Murderlon

Or use it today in the beta: https://www.npmjs.com/package/@uppy/svelte/v/4.0.0-beta.1

Murderlon avatar Apr 25 '24 09:04 Murderlon

Or use it today in the beta: https://www.npmjs.com/package/@uppy/svelte/v/4.0.0-beta.1

I tried that but am getting Cannot read properties of undefined (reading 'id')

TypeError: Cannot read properties of undefined (reading 'id')
    at Uppy.removePlugin (file:///Users/user/project/node_modules/@uppy/core/lib/Uppy.js:1031:42)
    at uninstallPlugin (/Users/user/project/node_modules/@uppy/svelte/src/components/DragDrop.svelte:24:18)
    at /Users/user/project/node_modules/@uppy/svelte/src/components/DragDrop.svelte:29:19
    at run (/Users/user/project/node_modules/svelte/src/runtime/internal/utils.js:41:9)
    at Array.forEach (<anonymous>)
    at Module.run_all (/Users/user/project/node_modules/svelte/src/runtime/internal/utils.js:53:6)
    at Object.render (/Users/user/project/node_modules/svelte/src/runtime/internal/ssr.js:165:4)
    at Module.render_response (/Users/user/project/node_modules/@sveltejs/kit/src/runtime/server/page/render.js:171:29)
    at async Module.render_page (/Users/user/project/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:286:10)
    at async resolve (/Users/user/project/node_modules/@sveltejs/kit/src/runtime/server/respond.js:446:18)

with

<script lang="ts">
    import { DragDrop } from '@uppy/svelte';
    import Uppy from '@uppy/core';
    import '@uppy/core/dist/style.css';
    import '@uppy/drag-drop/dist/style.css';

    const uppy = new Uppy();
</script>

<DragDrop {uppy} />

cellulosa avatar May 17 '24 10:05 cellulosa

@cellulosa fixed in https://github.com/transloadit/uppy/pull/5186

Murderlon avatar May 21 '24 15:05 Murderlon

We're using "@uppy/svelte": "^4.0.2" and are encountering the following TypeScript error:

Svelte: Cannot find module '@uppy/svelte' or its corresponding type declarations

As a workaround, we have to include the following directive in our code:

// @ts-expect-error: The module '@uppy/svelte' has no type definitions available.

It would be great if official type definitions for @uppy/svelte could be provided so that we can avoid the need for this exception.

abudin avatar Oct 03 '24 07:10 abudin

Issue reported here: #5475.

Closing this as we did actually add types to the package and it's published. But in the meantime a different build error slipped in.

Murderlon avatar Oct 03 '24 08:10 Murderlon