Skip to content

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

Open
@brunnerh

Description

@brunnerh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions