Add setter to let variables accessors
Describe the problem
In Svelte 3/4 the export keyword created accessors for const variables and functions and created props for let variables and when using the accessors option the keyword also created accessors for let variables In Svelte 5, the export keyword only creates accessors, but unlike v4 accessors, v5 accessors only have read capacity, creating a feature disparity between versions
Describe the proposed solution
Add setters to accessors of variables declared using let exported from a component
Importance
would make my life easier
Exporting a let variable in v4 is a property.
The equivalent in v5 should not be an export but a $props() declaration.
(There also is a compiler option legacy.componentsApi which might have an effect on the behavior - see these docs. At the very least you would be able to use $set on the component.)
You still can export function-setters
export const setMyProp = (v) => { myProp = v; };
or an object with all [writable] props
export const options1 = someStateObject;
export const options2 = {
get myProp() { return myProp; },
set myProp(v) { myProp = v; },
};
This was a deliberate choice though I can't exactly remember the rationale. Adding the 5.0 milestone so that we reach a final decision on this before the semver window closes
This was originally requested in #10310 (the readonly version) and then implemented in #10523 but without any real rationale for one way or the other. The only one I could imagine is "it makes the difference between export { x } in regular modules and component instances even more drastic".
I would be ok with adjusting that so that $state exports are settable.