-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$props & $derived should use let instead of const #12121
Comments
This comes down to stylistic preference. I personally for example want to use We shouldn't be in the business of dictating these preferences, therefore closing. |
Javascript already has a muddy definition of const { value } = $props()
console.log(value) // 1
function doSomethingLater{
console.log(value) // 4
}
Silently converting the behavior of |
You think about it that way, I think about it completely different. For me it's that I as the user am not allowed to reassign the derived value / the prop, not that the value doesn't change. |
I've written a ESLint rule |
Describe the bug
At the moment (Svelte 5.0.0-next.162) both:
and
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 assignmentsCannot 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
Severity
annoyance
The text was updated successfully, but these errors were encountered: