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

Using a generic type as an argument to a Snippet breaks types generation of a component #12202

Open
tommyminds opened this issue Jun 27, 2024 · 3 comments
Assignees
Milestone

Comments

@tommyminds
Copy link

tommyminds commented Jun 27, 2024

Describe the bug

When I use a generic type as an argument to a snippet, svelte-package does not properly generate a Component.d.ts file for my component anymore.

While I understand the following test case is a bit weird, I do have several components where I use the type of one of the properties to determine the type that is passed to subsequent snippets.

Reproduction

<script lang="ts" generics="T">
	import type { Snippet } from 'svelte';

	let {
		data,
		someSnippet
	}: {
		data: T;
		someSnippet?: Snippet<[T]>;
	} = $props();
</script>

<div>{@render someSnippet?.(data)}</div>

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M1 Pro
    Memory: 72.55 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.1 - ~/.nvm/versions/node/v18.19.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v18.19.1/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v18.19.1/bin/npm
    pnpm: 9.3.0 - /opt/homebrew/bin/pnpm
    bun: 1.1.13 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.5
  npmPackages:
    svelte: ^5.0.0-next.1 => 5.0.0-next.166

Severity

blocking an upgrade

@paoloricciuti
Copy link
Member

I suspect this has something to do with language-tools I'll try to take a look later

@tommyminds
Copy link
Author

I found other cases where types are not generated anymore. There also seems to be an issue using ComponentProps for components that have a Snippet on their props. For example the following causes the outer component to not generate types anymore.

Outer.svelte

<script lang="ts">
	import type { ComponentProps } from 'svelte';
	import Inner from './Inner.svelte';
	let { foo }: ComponentProps<Inner> = $props();
</script>

Inner.svelte

<script lang="ts">
	import { type Snippet } from 'svelte';
	let {
		foo,
		footer
	}: {
		foo: string;
		footer?: Snippet;
	} = $props();
</script>

@dummdidumm
Copy link
Member

Investigating this. For some reason TypeScript seems to want to unpack the types when using the ComponentProps type, likely because of the infer used in there. That in combination with the generated d.ts output of the default export of components leads to TS breaking down somewhere. This not only happens for Snippet, it can happen for other imported types, too.
Not sure what a good fix could be yet.

@dummdidumm dummdidumm self-assigned this Jun 28, 2024
@dummdidumm dummdidumm added this to the 5.0 milestone Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants