Skip to content

Latest commit

 

History

History
113 lines (76 loc) · 2.32 KB

experimental-require-slot-types.md

File metadata and controls

113 lines (76 loc) · 2.32 KB
pageClass sidebarDepth title description
rule-details
0
svelte/experimental-require-slot-types
require slot type declaration using the `$$Slots` interface

svelte/experimental-require-slot-types

require slot type declaration using the $$Slots interface

  • This rule has not been released yet.

📖 Rule Details

This rule enforces the presence of the $$Slots interface if any slots are present in the component. This interface declares all of the used slots and their props and enables typechecking both in the component itself as well as all components that include it. The $$Slots interface is experimental and is documented in svelte RFC #38.

<!-- ✓ GOOD -->
<script>
  // eslint svelte/experimental-require-slot-types: "error"
</script>

<b>No slots here!</b>
<!-- ✓ GOOD -->
<script>
  // eslint svelte/experimental-require-slot-types: "error"

  interface $$Slots {
    default: Record<string, never>;
  }
</script>

<slot />
<!-- ✓ GOOD -->
<script lang="ts">
  // eslint svelte/experimental-require-slot-types: "error"

  interface $$Slots {
    default: { prop: boolean; };
  }
</script>

<slot prop={true} />
<!-- ✓ GOOD -->
<script lang="ts">
  // eslint svelte/experimental-require-slot-types: "error"

  interface $$Slots {
    named: Record<string, never>;
  }
</script>

<slot name = "named" />
<!-- ✗ BAD -->
<script>
  // eslint svelte/experimental-require-slot-types: "error"
</script>

<slot />

🔧 Options

Nothing.

🔍 Implementation