Skip to content

Svelte 5 Optional snippets in components #10660

Answered by brunnerh
ThomasPais asked this question in Q&A
Discussion options

You must be logged in to vote

The types "claim" that the snippets are required, change this:

- } = $props<{ header: Snippet; body: Snippet; footer: Snippet }>();
+ } = $props<{ header?: Snippet; body: Snippet; footer?: Snippet }>();

(Would also not assign null, either leave it unassigned or use undefined. Though with certain strict options undefined will not be equivalent to unset; you may have to include it in the type as Snippet | undefined.)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ThomasPais
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants