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

TypeScript + Snippet: Error about using uninitialized variable #2653

Open
webJose opened this issue Dec 24, 2024 · 1 comment
Open

TypeScript + Snippet: Error about using uninitialized variable #2653

webJose opened this issue Dec 24, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@webJose
Copy link

webJose commented Dec 24, 2024

Describe the bug

I started the investigation on this because of a different problem with TypeScript in one of my projects at work. While trying to reproduce the error "Cannot find name 'snippet name'. (ts2304)", I stumbled upon this one:

image

Reproduction

  1. npm create vite@latest
  2. npm i
  3. Add src/lib/Test.svelte.
  4. Add the below content to the new file.
<script lang="ts" module>
    export const reusable = _reusable;
</script>

{#snippet _reusable(x: number)}
    <div>{x}</div>
{/snippet}

I am guessing that, while the error is there, the export works fine, as it works fine in my work project with the arguably worse "Cannot find name" error.

Logs

No response

System Info

Not needed?

Severity

annoyance

@Wombosvideo
Copy link

You can do this instead (see documentation):

<script lang="ts" module>
    export { reusable };
</script>

{#snippet reusable(x: number)}
    <div>{x}</div>
{/snippet}

Or this, if you need to rename the export:

<script lang="ts" module>
    export { reusable_ as reusable };
</script>

{#snippet reusable_(x: number)}
    <div>{x}</div>
{/snippet}

@dummdidumm dummdidumm transferred this issue from sveltejs/svelte Jan 6, 2025
@dummdidumm dummdidumm added the bug Something isn't working label Jan 6, 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

3 participants