sveltejs/svelte

Symbol keys in state objects are not spread into rest props

Closed this issue · 0 comments

gka commented

Describe the bug

In JavaScript it is possible to spread Symbol keys into rest props:

const S = Symbol('key');
const a = { foo: 'bar', [S]: 42 }
const { foo, ...rest } = a;
console.log(rest[S]); // logs 42

But in Svelte this doesn't work:

<script>
  const S = Symbol('key');
	
  let a = $state({ foo: 'bar', [S]: 42 });
  $inspect('a[S]:', a[S]); // 42

  let { foo, ...rest } = $derived(a);
  $inspect('rest[S]:', rest[S]); // undefined
</script>

Reproduction

https://svelte.dev/playground/3798e7ae88584fd887cc81645c9522cc?version=5.43.2

Logs

System Info

All browsers, all Svelte 5.x versions (as far as I can tell)

Severity

annoyance