Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions documentation/docs/03-template-syntax/06-snippet.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,29 @@ Snippets implement the `Snippet` interface imported from `'svelte'`:

With this change, red squigglies will appear if you try and use the component without providing a `data` prop and a `row` snippet. Notice that the type argument provided to `Snippet` is a tuple, since snippets can have multiple parameters.

We can tighten things up further by declaring a generic, so that `data` and `row` refer to the same type:
We can tighten things up further by declaring a Fruit type, so that `data` and `row` refer to the same type. Now a row snippet will error if the shape is not used.

```svelte
<script lang="ts" generics="T">
<script lang="ts">
import type { Snippet } from 'svelte';

type Fruit = {
name: string;
qty: number;
price: number;
}

let {
data,
children,
row
}: {
data: T[];
data: Fruit[];
children: Snippet;
row: Snippet<[T]>;
row: Snippet<[Fruit]>;
} = $props();
</script>

```

## Exporting snippets
Expand Down