Skip to content

Svelte 5: Cannot reassign or bind to each block argument in runes mode. What should I use instead? #11430

@frederikhors

Description

@frederikhors

Describe the bug

In Svelte 4 app I was using:

{#each players || [] as player, i}
    <FormPlayer index={i} bind:player />
{/each}

Now with Svelte 5 it errors with:

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`)

Why?

Should I use the below instead?

{#each players || [] as player, i}
    <FormPlayer index={i} bind:player={players[i]} />
{/each}

Also if I use the latter one player is unused and I get the ts warning:

'player' is declared but its value is never read. ts(6133)

Plus, with the latter one I get another typscript warning:

'players' is possibly 'null' or 'undefined'. ts(18049)

even if I'm already inside an {#each players.

There is no docs on this on https://svelte-5-preview.vercel.app/docs, right?

System Info

`"svelte": "5.0.0-next.120"`

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions