Skip to content

Snippets and their argument types not correctly resolved from generic legacy components #2716

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

Open
brunnerh opened this issue Mar 14, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@brunnerh
Copy link
Member

Describe the bug

Using a legacy component with slots via snippets, the available snippets may not be resolved correctly and arguments passed to the snippets end up as any.

Reproduction

<!-- loader.svelte -->
<script lang="ts" generics="T">
	interface $$Slots {
		default: { value: T },
		loaded: { value: T },
		loading: { },
		error: { error: any },
	}

	export let promise: Promise<T>;
</script>

{#await promise}
	<slot name="loading">
		Loading...
	</slot>
{:then value}
	<slot {value} />
	<slot name="loaded" {value} />
{:catch}
  Error!
{/await}
<script lang="ts">
  import Loader from './loader.svelte';

  const delay = (ms: number) => new Promise(resolve => setTimeout(() => resolve(ms), ms));

  const promise = delay(1000).then(() => "resolved");
</script>

<Loader promise={promise}>
  <!--
    Error on `loading`:
    Object literal may only specify known properties, and 'loading' does not exist
    in type '{ promise: Promise<string>; } & { children?: any; }'. ts(2353)
  -->
  {#snippet loading()}
    Loading text...
  {/snippet}

  <!--
    Error on `value`:
    <!-- Binding element 'value' implicitly has an 'any' type. ts(7031)
  -->
  {#snippet loaded({ value })}
    Text: {value}
  {/snippet}

  {#snippet error()}
    Error.
  {/snippet}
</Loader>

(The runtime behavior is correct.)

Expected behaviour

  • loading is detected as a valid slot/snippet.
  • value is generically typed correctly (here string).

System Info

  • OS: Windows 10, 64bit
  • IDE: VSCode 1.98.2

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

Extension & svelte-check yield same errors.

If the loading snippet is not there, the next snippet will show an error, only promise & children are detected as valid properties.

@brunnerh brunnerh added the bug Something isn't working label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant