Improved error when attempting to export $derived state as a let?
#15842If you use export const foo = $derived(...)
to attempt to expose derived state on a component instance, you get a helpful error message about instead needing to export a function that returns the derived state. However, if you write export let foo = $derived(...)
instead, the compiler thinks you are trying to use the export
syntax to define a prop, and directs you to use $props()
instead.
Adjacently, something like export const foo = 42
(in runes mode) is allowed by the compiler, which seems to just expose that value on the component instance like export function foo() { ... }
would, and I don't know whether that was intentionally left in as a feature.
I'm not sure, entirely. There certainly are situations where the best thing would be to continue to throw the error about how this isn't the right way to define props anymore. But I think people using let
s for $derived()
s isn't that uncommon, and so using let
vs const
to decide what's happening here isn't ideal.
nice to have