Skip to content

Issue with VSCode Incorrectly Reporting bind:clientWidth as an ErrorΒ #2741

@MineYuanlu

Description

@MineYuanlu

Describe the bug

I followed the documentation (https://svelte.dev/docs/svelte/bind#Function-bindings) to write code using bind:clientWidth, but I encountered an error:

Object literal may only specify known properties, and '"bind:clientWidth"' does not exist in type 'HTMLProps<"div", HTMLAttributes<any>>'.ts(2353)

However, if I ignore the error reported by VSCode, the page works as expected.

Additionally, I noticed that the following code works fine:

<div bind:clientWidth={w}>content</div>

But when I use it like this, it doesn't work:

<div bind:clientWidth={null, (v) => w=v}>content</div>

Version:

  • VSCode: 1.98.2 (Universal)
  • svelte.svelte-vscode: 109.5.3 (2025-03-06, 23:40:48)

Reproduction

<script lang="ts"> let w=$state(0); </script>
w=v}>content

Logs

System Info

System:
    OS: macOS 14.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 87.77 MB / 16.00 GB
    Shell: 5.2.32 - /opt/homebrew/bin/bash
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    npm: 11.0.0 - ~/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 9.15.1 - ~/.nvm/versions/node/v20.17.0/bin/pnpm
  Browsers:
    Chrome: 135.0.7049.42
    Safari: 17.0
  npmPackages:
    svelte: ^5.0.0 => 5.25.3

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions