Closed as not planned
Description
Describe the problem
When converting a component from svelte 4 to svelte 5 (runes mode), I noticed the each_item_invalid_assignment error. The error message says "Cannot reassign or bind to each block argument in runes mode. Use the array and index variables instead (e.g. array[i] = value instead of entry = value)". That means it is no longer possible to write
<script lang="ts">
interface Props {
values: number[];
}
let { values }: Props = $props();
</script>
{#each values as value}
<button onclick={() => value++}>Click me!</button>
{/each}
Instead, I now have to write
<script lang="ts">
interface Props {
values: number[];
}
let { values }: Props = $props();
</script>
{#each values as value, i}
<button onclick={() => values[i]++}>Click me!</button>
{/each}
Describe the proposed solution
For me, it seems like it would be fairly straight forward to just let the compiler replace value
with values[i]
. That way, the code would be a little cleaner to write and would stay compatible with the svelte 4 way, while at the same time satisfy the underlying constraint that makes this necessary.
Importance
nice to have
Metadata
Metadata
Assignees
Labels
No labels