language-tools: šŸ› BUG: Svelte components using .d.ts declarations with SvelteComponentTyped are not supported

Describe the Bug

SvelteComponentTyped’s constructor expect a target attribute to be passed. I am unfortunately not super knowledgeable in Svelte’s internals to know what it’s used for, but one thing is sure: We don’t pass it in Astro files.

Looking at Svelte2tsx tests, it seems like passing it a dummy value is okay, but the problem is that unlike Svelte, we don’t know if a components needs it or not (and passing it to all components would lead to errors for other frameworks).

A possible solution would be to patch the definition of SvelteComponentTyped when we load the snapshot for Svelte’s dev.d.ts, but I wouldn’t be surprised if that brings in more issues šŸ¤”

Workaround

Importing the component directly works, provided that it’s exported. ex: import Theme from 'carbon-components-svelte/src/Theme/Theme.svelte';

Steps to Reproduce

  1. Import a component from a Svelte library with typings, ex: import {Ā Theme } from "carbon-components-svelte"
  2. Use it in the template
  3. Error! Says target is required even though that props doesn’t exist

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 15 (3 by maintainers)

Most upvoted comments

That package is very weirdly packaged, it only has a single export using a non-standard export name and it declares its types using a fake module

https://github.com/jacobmischka/svelte-flatpickr/blob/master/package.json#L32-L36

I don’t really know how we would support that without implementing Svelte’s module resolution I assume. If the package just exposed the files normally, you could just import the Svelte components.