Closed
Description
Hello,
A couple of months ago (July 2021), the Svelte team added the ability to specify generics types when using TypeScript.
RFC: sveltejs/rfcs#38
Thread: sveltejs/language-tools#442
Exemple
<!-- ForEach.svelte -->
<script lang="ts">
type T = $$Generic;
export let items: T[];
</script>
{#each items as item}
<slot {item} />
{/each}
<!-- App.svelte -->
<script lang="ts">
import ForEach from "$lib/components/ForEach.svelte";
import type { Todo } from "$lib/todo.service";
let todos: Todo[] = [];
</script>
<ForEach items={todos} let:item>
<!-- item is correctly typed as Todo here -->
<p>{item.name}</p>
</ForEach>
Issue
When using this new feature, eslint-plugin-svelte3
complains with error no-undef
.
Workaround
Disabling the error manually:
<script lang="ts">
type T = $$Generic; /* eslint-disable-line no-undef */
export let items: T[];
</script>
{#each items as item}
<slot {item} />
{/each}
Metadata
Metadata
Assignees
Labels
No labels