-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Open
Description
Describe the bug
Trying to pass in a generic type to a snippet when I have a <script module> in the same svelte file results in odd behaviour
All tested with typescript 5.9.3
Reproduction
This results in a typescript error of Cannot find name 'T'.ts(2304) type T = /*unresolved*/ any
on the snip arg (note that a {@const}
instead of arg also errors, type T is just not visible)
<script lang="ts" module></script>
<script lang="ts" generics="T">
import type { Snippet } from "svelte";
let { snip = defaultSnip }: { snip: Snippet<[T]> } = $props();
</script>
{#snippet defaultSnip(generic: T)}
Hello
{/snippet}
Removing the <script lang="ts" module></script>
makes the issue go away completely.
Referencing a value (any value, unrelated to the generic) from the component like this also makes the issue go away
<script lang="ts" module></script>
<script lang="ts" generics="T">
import type { Snippet } from "svelte";
let { snip = defaultSnip }: { snip: Snippet<[T]> } = $props();
const text = "Hello"
</script>
{#snippet defaultSnip(generic: T)}
{text}
{/snippet}
Logs
System Info
System:
OS: macOS 15.6.1
CPU: (8) arm64 Apple M2
Memory: 571.47 MB / 24.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 24.4.1 - /opt/homebrew/bin/node
npm: 11.4.2 - /opt/homebrew/bin/npm
bun: 1.2.18 - ~/.bun/bin/bun
Browsers:
Chrome: 140.0.7339.214
Safari: 18.6
Severity
blocking an upgrade
Metadata
Metadata
Assignees
Labels
No labels