sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
79.6k stars 4.21k forks source link

Svelte 5: Action parameters type inferred as 'any' despite explicit typing #13268

Open colinlienard opened 1 month ago

colinlienard commented 1 month ago

Describe the bug

When defining an Action with explicit parameter types, the compiler still infers the parameters as any, leading to type errors when accessing properties:

image

But this seems to happen only in the IDE because when running svelte-check there are no errors.

Reproduction

https://github.com/colinlienard/svelte-5-repro in src/App.svelte

Logs

Property 'foo' does not exist on type 'unknown'

System Info

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M2
    Memory: 505.70 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.11.0/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
    pnpm: 9.0.6 - ~/.nvm/versions/node/v20.11.0/bin/pnpm
    bun: 1.1.26 - ~/.nvm/versions/node/v20.11.0/bin/bun
  Browsers:
    Chrome: 128.0.6613.138
    Safari: 17.6
  npmPackages:
    svelte: 5.0.0-next.246 => 5.0.0-next.246

Severity

annoyance

hmnd commented 1 week ago

Experiencing this too... Very strange bug, as I don't see anything wrong with Action's declaration.