Skip to content

Computed property names in Svelte each block destructuring #487

@hyunbinseo

Description

@hyunbinseo

When using computed property names ([id]) in Svelte's each block destructuring pattern, the square brackets are removed.

- {#each objs as { [id]: value }}
+ {#each objs as { id: value }}

This causes a syntax error:

<script lang="ts">
  const ids = ['a', 'b', 'c'] as const;
  const objs = [{ a: 1 }, { b: 2 }, { c: 3 }];
</script>

{#each ids as id}
  <tr>
    <!-- Property 'id' does not exist on type (…) -->
    {#each objs as { id: value }}
      <td>{value}</td>
    {/each}
  </tr>
{/each}
devDependencies:
prettier 3.5.2
prettier-plugin-svelte 3.3.3

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