-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Describe the bug
The bug refers to this context: https://svelte.dev/tutorial/svelte/spread-props
The intuitive behavior after let { name, ...stuff } = $props();
is to not be able to access stuff.name
.
As expected, looking at the keys of the stuff
object, name
doesn't show up.
This has been discussed in this Discord thread: https://discord.com/channels/457912077277855764/1424084421711237241
Another person described that:
Looking at the output, both
name
andstuff.name
are compiled to$$props.name
:
$.set_text(text_3, $$props.name); $.set_text(text_4, $$props.name);

Reproduction
- A component that accepts props and destructures them in at least one variable and a rest property:
<script>
let {name, version, ...stuff} = $props()
</script>
- Passing an object to the component where it is used:
<script>
import Component from './Component.svelte'
const pkg = {
name: 'svelte',
version: 5,
description: 'blazing fast',
website: 'https://svelte.dev'
};
</script>
<Component {...pkg}/>
- Accessing the individually declared property on the rest prop:
name === stuff.name
: {name === stuff.name}
'name' in stuff
: {'name' in stuff}
https://svelte.dev/playground/a601dd33221b45d284c14012951818bb
Logs
System Info
Playground
Severity
annoyance