Skip to content

TypeScript: Build fails with bindable_invalid_location on destructuring assignment with a rest operator #15782

@CosmoMyzrailGorynych

Description

@CosmoMyzrailGorynych

Describe the bug

My issue is similar to #15209, but more nuanced. My case emerges while trying to use @xyflow/svelte@next package.

After switching to this xyflow version, Svelte fails with an error bindable_invalid_location. (See logs.) The actual code referenced in the logs does use $bindable in the props declaration:

  let {
    width,
    height,
    proOptions,
    selectionKey,
    deleteKey,
    panActivationKey,
    multiSelectionKey,
    zoomActivationKey,
    paneClickDistance = 1,
    nodeClickDistance = 1,
    onmovestart,
    onmoveend,
    onmove,
    oninit,
    onnodeclick,
    onnodecontextmenu,
    onnodedrag,
    onnodedragstart,
    onnodedragstop,
    onnodepointerenter,
    onnodepointermove,
    onnodepointerleave,
    onselectionclick,
    onselectioncontextmenu,
    onedgeclick,
    onedgecontextmenu,
    onedgepointerenter,
    onedgepointerleave,
    onpaneclick,
    onpanecontextmenu,
    panOnScrollMode = PanOnScrollMode.Free,
    preventScrolling = true,
    zoomOnScroll = true,
    zoomOnDoubleClick = true,
    zoomOnPinch = true,
    panOnScroll = false,
    panOnDrag = true,
    selectionOnDrag = true,
    connectionLineComponent,
    connectionLineStyle,
    connectionLineContainerStyle,
    connectionLineType = ConnectionLineType.Bezier,
    attributionPosition,
    children,
    nodes = $bindable([]),
    edges = $bindable([]),
    viewport = $bindable(undefined),
    ...props
  }: SvelteFlowProps & HTMLAttributes<HTMLDivElement> = $props();

Reproduction

⚠️👉 Now look, I am able to reproduce the same error only if I add ...theRest:

{sausages} sausages {#if theRest} with {Object.keys(theRest).join(', ')}{/if}

<script lang="ts">
type A = {
    sausages: number;
    ketchup?: boolean;
    mayonnaise?: boolean;
};

let {
    sausages = $bindable(1),
    ...theRest
}: A = $props();
</script>
00:29:14 [vite] (client) Pre-transform error: src/App.svelte:14:32 `$bindable()` can only be used inside a `$props()` declaration
https://svelte.dev/e/bindable_invalid_location
  Plugin: vite-plugin-svelte
  File: src/App.svelte:14:32
   12 |      return t;
   13 |  };
   14 |  let _a = $props(), { sausages = $bindable(1) } = _a, theRest = __rest(_a, ["sausages"]);
                                                     ^
   15 |  </script>

👉 Using JS only instead of TS magically fixes the issue.

Logs

X [ERROR] node_modules/@xyflow/svelte/dist/lib/components/EdgeReconnectAnchor/EdgeReconnectAnchor.svelte:16:42 `$bindable()` can only be used inside a `$props()` declaration
https://svelte.dev/e/bindable_invalid_location [plugin vite-plugin-svelte:optimize-svelte]

    node_modules/@xyflow/svelte/dist/lib/components/EdgeReconnectAnchor/EdgeReconnectAnchor.svelte:16:42:
      16 │ ...pe, reconnecting = $bindable(false), po...
         ╵                        ^

  The plugin "vite-plugin-svelte:optimize-svelte" was
  triggered by this import

    node_modules/@xyflow/svelte/dist/lib/components/EdgeReconnectAnchor/index.js:1:47:
      1 │ ...chor } from './EdgeReconnectAnchor.svelte';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] node_modules/@xyflow/svelte/dist/lib/container/SvelteFlow/SvelteFlow.svelte:27:855 `$bindable()` can only be used inside a `$props()` declaration
https://svelte.dev/e/bindable_invalid_location [plugin vite-plugin-svelte:optimize-svelte]

    node_modules/@xyflow/svelte/dist/lib/container/SvelteFlow/SvelteFlow.svelte:27:855:
      27 │ ... children, nodes = $bindable([]), edges...
         ╵                        ^

  The plugin "vite-plugin-svelte:optimize-svelte" was
  triggered by this import

    node_modules/@xyflow/svelte/dist/lib/container/SvelteFlow/index.js:1:38:
      1 │ ...as SvelteFlow } from './SvelteFlow.svelte';

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H   
    Memory: 42.32 GB / 63.73 GB
  Binaries:
    Node: 20.13.1 - C:\Program Files\nodejs\node.EXE     
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD        
    bun: 1.2.10 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.1
    (but I'm using Firefox, hello???)
  npmPackages:
    svelte: ^5.27.0 => 5.27.0

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