You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the only documented way to create default props is by destructuring them. While this is fine for small components, larger components benefit from using the props. prefix.
<scriptlang="ts">
const props: { name:string; age?:number; // how to give age a default value?} =$props();
</script>
<div>{props.name}</div>
<div>{props.age}</div>
Something similar could be added to the Svelte runes API.
Importance
i cannot use svelte without it
The text was updated successfully, but these errors were encountered:
rodrigocfd
changed the title
Standard way to provide default prop values with TypeScript
Feature request: standard way to provide default prop values with TypeScript
Dec 26, 2024
Describe the problem
Currently, the only documented way to create default props is by destructuring them. While this is fine for small components, larger components benefit from using the
props.
prefix.I mean, I can do this:
...which gives me the correct assignment and proper typing, but it's just an ugly React hack.
Describe the proposed solution
Vue 3 provides the
withDefaults
API, which is a rather elegant solution to the problem:Something similar could be added to the Svelte runes API.
Importance
i cannot use svelte without it
The text was updated successfully, but these errors were encountered: