romkor / svelte-portal

Svelte component for rendering outside the DOM of parent component
https://svelte.dev/repl/407576d4fa984cfb97dcdd3da98e833e
MIT License
444 stars 22 forks source link

Type definitions missing #128

Closed cshaa closed 2 years ago

cshaa commented 2 years ago

When I try to import the package in my Svelte project, I get the following error:

Could not find a declaration file for module 'svelte-portal'.
'node_modules/svelte-portal/src/main.cjs.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/svelte-portal` if it exists or add a new declaration (.d.ts) file containing `declare module 'svelte-portal';`

Looking at the svelte-portal folder in node_modules, there indeed isn't any .d.ts file.

This is weird, sveltekit package should produce both a compiled .svelte file as well as .d.ts file. (For comparison, projects like svelte-material-ui do ship the .d.ts files, and therefore work out-of-the-box.) Could you, by any chance, publish the package with the type definitions?

cshaa commented 2 years ago

I've created a new SvelteKit project and copypasted Portal.svelte there. It does the trick, now it includes the type definitions. You can check my fork, or get it from NPM.

@romkor If you're interested in migrating the project to SvelteKit (as recommended in this tutorial), I'll glagly assist you. If you want to modify your current build process to also produce .d.ts, that's also fine I guess :)

romkor commented 2 years ago

Did you try import Portal from “svelte-portal/src/Portal.svelte”?

cshaa commented 2 years ago

Nice, that does the trick! I guess there's no problem, then :) However, you might consider making it work even with import Portal from "svelte-portal".

romkor commented 2 years ago

Trick is to keep backward compatibility for javascript users. Maybe it can be good idea just add types definition by hands))

cshaa commented 2 years ago

I think that any modern Svelte project can handle the packages generated by SvelteKit. So, personally, I'd consider bumping the major version to 3 and migrating to the new structure. If it breaked anyone's setup, they'd either stay on the last version of svelte-portal, or would be motivated to use an up-to-date version of Svelte in their project.

However, you might feel it differently. If you want to just add the type definitions as a separate file, the Plot.svelte.d.ts file from my fork might come in handy. I can also make a PR adding the type definitions if you want me to.

romkor commented 2 years ago

PR with Portal.svelte.d.ts file will be useful. Thanks!

cshaa commented 2 years ago

Sorry for the delay! I've created PR #135.

romkor commented 2 years ago

Thanks, merged!