Skip to content

Improved error when attempting to export $derived state as a let? #15842

Description

@Conduitry

Describe the problem

If 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.

Describe the proposed solution

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 lets for $derived()s isn't that uncommon, and so using let vs const to decide what's happening here isn't ideal.

Importance

nice to have

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