Skip to content

Separately declared property can be accessed in rest property but doesn't show up when inspecting #16895

@24online24

Description

@24online24

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 and stuff.name are compiled to $$props.name:
$.set_text(text_3, $$props.name); $.set_text(text_4, $$props.name);

Image

Reproduction

  1. A component that accepts props and destructures them in at least one variable and a rest property:
<script>
	let {name, version, ...stuff} = $props()
</script>
  1. 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}/>
  1. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions