Svelte · Senior · Question 59 of 75
How do you type a component that accepts a generic list and a row snippet?
<script lang="ts" generics="T">
import type { Snippet } from "svelte";
let { items, row }: { items: T[]; row: Snippet<[T]> } = $props();
</script>- ✓Correct answer: Use the
genericsattribute on<script>and theSnippet<[T]>type for the snippet prop - 2Generics aren't supported in Svelte
- 3Use
anyeverywhere
Explanation
Consumers then get type checking for the snippet's parameter based on the items passed in.