We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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.
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()
would make my life easier
The text was updated successfully, but these errors were encountered:
Shouldn't it then be two components? Maybe one wrapping another, or with common logic in "private" .ts file, or something.
Sorry, something went wrong.
And, to clarify, the problem is only with Typescript. You can do
type Props = | { lowerValue: string; upperValue: string; value?: never; } | { value: string lowerValue?: never; upperValue?: never; };
Which will give you the desired result. Not perfect, but totally working.
No branches or pull requests
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.
This works fine for simple types, but if you had a union type like so:
Then you can not de-structure.
Describe the proposed solution
Solution:
Add an interface for declaring $bindables without de-structuring.
For Example:
Or:
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: