Skip to content

"$$slots" variable throws "no-undef" error #107

Closed
@sounisi5011

Description

@sounisi5011

Following the official documentation, I have created the following components for my project.

{#if $$slots.labelText}
  <!-- svelte-ignore a11y-label-has-associated-control -->
  <label>
    <slot name="labelText" />
    <slot />
  </label>
{:else}
  <slot />
{/if}

This component will compile and run successfully.
However, when I used [email protected], I got a no-undef error.

./LabelInputArea.svelte
  1:6  error  '$$slots' is not defined  no-undef

To developers who have encountered similar problems:

The $$slots variable can be used within the script element.
So, I avoided this error by rewriting the following code.

<script lang="ts">
  const slots = $$slots;
</script>

{#if slots.labelText}
  <!-- svelte-ignore a11y-label-has-associated-control -->
  <label>
    <slot name="labelText" />
    <slot />
  </label>
{:else}
  <slot />
{/if}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions