Open
Description
Describe the bug
If I want to export a shared state, the normal way is to do like this:
Option 1
// rune.svelte.tsexportconstrune=<T>(initialValue: T)=>{let_rune=$state(initialValue);return{getvalue(){return_rune;},setvalue(v: T){_rune=v;}};};
Option 2
This also works:
// rune.svelte.tsexportconstrune=<T>(initialValue: T)=>{const_rune=$state({value: initialValue});return_rune;};
Option 3
However, if I simplify option 2, I get a compile error:
exportconstrune=<T>(initialValue: T)=>$state({value: initialValue});// ORexportconstrune=<T>(initialValue: T)=>{return$state({value: initialValue});};
I get the error:
$state(...)` can only be used as a variable declaration initializer or a class field
I would expect Option 3 to compile the exact same way as option 2 !?
Reproduction
Logs
Error message above.
System Info
Svelte 5.2.0
Severity
annoyance