Skip to content

$props & $derived should use let instead of const #12121

Closed as not planned
Closed as not planned
@bfanger

Description

@bfanger

Describe the bug

At the moment (Svelte 5.0.0-next.162) both:

const { value } = $props()

and

let { value } = $props()

work without issue or warning.

Allowing const here is confusing as the meaning in Javascript is that the value is never re-assigned, but in case of $props and $derived the value will be reassigned. It's not something we do, but something the Svelte reactivity system does.

Although I think let is the correct declaration type, const has the benefit of blocking assignments Cannot assign to constant and we shouldn't reassign most props or derived values.

For derived values the compiler already protects us against that Cannot assign to derived state 🎉
( It would be nice if the compiler also protects us against assigning against assigning values to nonbindable props.)

Reproduction

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAE42QwWrDMAyGX0WIHhIa6uWaOYGxvcW8Q-Y61MyRjS0PSsi7DzdtYLDDDjro1_dLP1pwss4k7N4XpHE22OFLCNggX0Np0rdxbLDB5HPURZFJRxt4UKTYzsFHhjebghuvMEU_g8KTuAunza2wsKWcYdA-E0MPh8Qjm-qpflZUZlMmzdYTWNLRzIa4qmG5OXnzHHtoC8yrIin2GPJxfrlhK4gifmZmT-BJO6u_-mXfug7HVoptPGCDsz_byZozdhyzWZv9D_e1__2F9pR4z9DDIUQfUlX_yqpIXtrhtTDdg5Xi0v4R5GP9AYfFjG-cAQAA

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M3 Pro
    Memory: 112.45 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.6.2 - /opt/homebrew/bin/node
    Yarn: 1.22.21 - ~/Library/pnpm/yarn
    npm: 10.8.1 - /opt/homebrew/bin/npm
    pnpm: 9.4.0 - ~/Library/pnpm/pnpm
  Browsers:
    Brave Browser: 125.1.66.110
    Chrome: 126.0.6478.63
    Safari: 17.5
  npmPackages:
    svelte: 5.0.0-next.162 => 5.0.0-next.162

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