Skip to content

Error when creating an accessor for an prop #10311

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

Closed
Thiagolino8 opened this issue Jan 26, 2024 · 4 comments · Fixed by #10430
Closed

Error when creating an accessor for an prop #10311

Thiagolino8 opened this issue Jan 26, 2024 · 4 comments · Fixed by #10430
Milestone

Comments

@Thiagolino8
Copy link

Describe the bug

When creating an accessor to an prop without using svelte:options, If you create an accessor for a binded prop using export its value becomes an internal function, if you try to export a prop that is used as an object the compiler tries to export using a variable that is never declared

Reproduction

repl

Logs

No response

System Info

Svelte v5.0.0-next.40

Severity

annoyance

@dummdidumm dummdidumm added this to the 5.0 milestone Feb 6, 2024
@dummdidumm
Copy link
Member

What's the use case? What's the Svelte 4 equivalent? I think exporting things from $props() should be a compiler error.

@dummdidumm dummdidumm added the awaiting submitter needs a reproduction, or clarification label Feb 6, 2024
@Thiagolino8
Copy link
Author

The use would be to create individual prop accessors instead of all at once using the accessors option

@dummdidumm
Copy link
Member

It would be confusing to explain why you can export $state like that from a component and it behaves differently compared to an export from a module. The "workaround" is to just export a function which returns the current value, which also better conveis the "this can change" notion -> this code should be a compiler error.

@dummdidumm dummdidumm removed the awaiting submitter needs a reproduction, or clarification label Feb 8, 2024
dummdidumm added a commit that referenced this issue Feb 8, 2024
disallow exporting props, derived and reassigned state from within components
closes #10310, closes #10311, closes #10293
@Rich-Harris
Copy link
Member

note that we reverted this change in #10523, this will now work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants