Skip to content

Allow declaration of $bindable fields on the union type prop. #15209

@Aron-Lomner

Description

@Aron-Lomner

Describe the problem

Problem:
It is not possible to have a $bindable field on the union portion of a Prop.

Explanation:
Svelte only allows declaring a prop field as $bindable from within a de-structuring.

  let { lowerValue = $bindable(), upperValue = $bindable(), value = $bindable() }: Props = $props();

This works fine for simple types, but if you had a union type like so:

type Props =
    | {
        lowerValue: number;
        upperValue: number;
      }
    | { value: number };

Then you can not de-structure.

Describe the proposed solution

Solution:
Add an interface for declaring $bindables without de-structuring.
For Example:

type Props =
   | {
       lowerValue: $bindable(number) ;
       upperValue: $bindable(number);
     }
   | { value: $bindable(number) };

Or:

type Props =
    | {
        lowerValue: number ;
        upperValue: number;
      }
    | { value: number };
  let props: Props = $props();
  props.lowerValue = $bindable()

Importance

would make my life easier

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