Skip to content

Cannot bind to MemberExpression #14341

Closed as not planned
Closed as not planned
@hanielu

Description

@hanielu

Describe the bug

When trying to bind: to a MemberExpression (e.g bind:checked={checked(true).current}) Svelte throws the error:

Can only bind to an Identifier or MemberExpression

Here's a simple snippet highlighting the issue:

<script>
  const state = $state({
    checked: true,
  });

  const store = Object.fromEntries(
    Object.keys(state).map(key => [
      key,
      (current = false) => {
        return current
          ? {
              get current() {
                return state[key];
              },
              set current(value) {
                state[key] = value;
              },
            }
          : state[key];
      },
    ])
  );
</script>

<!-- This causes the error ❌ -->
<input type="checkbox" bind:checked={store.checked(true).current} />

Reproduction

Here's a REPL

Logs

No response

System Info

Playground version 5.2.2

Severity

annoyance

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