Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1655

How to assign default prop values with Svelte 5 and TypeScript?

$
0
0

Suppose I have the following Svelte 5 component:

<script lang="ts">  const props: {    name: string;    age?: number;  } = $props();</script><div>Name: {props.name}</div><div>Age: {props.age}</div>

I want props.age to have the default value of 40.

How can I do that, while keeping the props. prefix to access the values?


Viewing all articles
Browse latest Browse all 1655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>