Skip to content

Snippet doesn't satisfy the Snippet type, apparentlyΒ #13759

@webJose

Description

@webJose

Describe the bug

In a class, I have the following overload:

    show(content: string | Snippet): void;

This is a SvelteKit project that produces an NPM library package. When the project is built, the dist folder contains:

    show(content: string | Snippet): void;

Great so far. Now the class is imported in a Vite + Svelte project by importing it from the built NPM package. The importer declares the following snippet:

{#snippet overlay()}
    <Spinner text="Loading..." variant="primary" />
{/snippet}

Then, this snippet is used in a call to show():

        systemOverlay.show(overlay);

TypeScript is now unhappy. The word "overlay" has the squiggly red line and the error says:

Overload 1 of 3, '(content: string | Snippet<[]>): void', gave the following error.
Argument of type '() => ReturnType<import("svelte").Snippet>' is not assignable to parameter of type 'string | Snippet<[]>'.
Type '() => ReturnType<import("svelte").Snippet>' is not assignable to type 'Snippet<[]>'.

So the snippet overlay is typed as a function whose return type is the return type of the Snippet type from svelte, instead of just being a snippet.

Reproduction

Hopefully the above information is enough to reproduce? Do let me know, though.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
    Memory: 16.62 GB / 39.73 GB
  Binaries:
    Node: 20.17.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.105)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    svelte: ^5.0.5 => 5.0.5

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions