Skip to content

Conflict between const and $bindable #15754

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
AsaMitakaIT opened this issue Apr 13, 2025 · 3 comments
Closed

Conflict between const and $bindable #15754

AsaMitakaIT opened this issue Apr 13, 2025 · 3 comments

Comments

@AsaMitakaIT
Copy link

AsaMitakaIT commented Apr 13, 2025

This comes down to stylistic preference. I personally for example want to use const for components that only have readonly props. Or I prefer to use const for $derived because for me it better communicates that this is a readonly value, not necessarily that the value itself never changes.

We shouldn't be in the business of dictating these preferences, therefore closing.

Originally posted by @dummdidumm in #12121

<script lang="ts">
    let { options, selected = $bindable() }: { options: string[], selected: number } = $props();
</script>

In this scenario, I’d like to define both const options and let selected simultaneously, but I can’t invoke $props twice. I suppose there’s currently no solution for this?

@AsaMitakaIT AsaMitakaIT changed the title The contradiction between const and $bindable Conflict between const and $bindable Apr 13, 2025
@Ocean-OS
Copy link
Contributor

I guess you could do something like this:

<script lang="ts">
    let { options: _options, selected = $bindable() }: { options: string[], selected: number } = $props();
    const options = $derived(_options); 
</script>

@jjones315
Copy link

jjones315 commented Apr 13, 2025

For a lot of props you could do
<script lang="ts"> let { selected = $bindable(), …_readonlyProps }: { prop1: string, prop2:number, selected: number } = $props(); const { prop1, prop2, …restProps} = $derived(_readonlyProps); </script>

Sorry about formatting, on mobile.

@dummdidumm
Copy link
Member

There's no solution to this, no, workarounds like shown in this thread exist though. Closing as unactionable; also related to #15675

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2025
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

No branches or pull requests

4 participants