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>

Explanation

Consumers then get type checking for the snippet's parameter based on the items passed in.

Further reading

Problem with a question

Svelte · Senior · question 59

Test yourself

Take the Svelte · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz