-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Require props to be bound #8218
Comments
Given the following typed component example: export default class Dropdown extends SvelteComponentTyped<{
[x: string]: any;
selectedId: any;
invalid?: boolean;
size?: "sm" | "xl" | "lg";
// ...
}> We know that:
With Sveld, we collect and document "Reactive" props by determining which variables are I don't know if there's a way to indicate |
Wouldn't it be more typescript-y to define non-reassignable variables the |
In Svelte 5, props are only bindable if they are marked as such, so I'll close this as completed. (We don't differentiate between static and non-static props but I'm not sure how useful such a distinction would be.) |
It's always nice to see how you come up with clever solutions! |
Describe the problem
When creating a component, I notice that there are essentially three types of props:
bind:name
, otherwise the component doesn't work properlybind:name
key="configValue"
But when someone is consuming the component, they won't know which kind each prop should be, or at least if it should be type 1 or not.
Describe the proposed solution
It would be nice if Svelte provided a way to make component props required to be bound, to ensure that type 1 is used.
I understand it would be hard though to add this kind of metadata within the javascript syntax. For typescript, maybe it could be something like:
Alternatives considered
A convention like capitalized props for type 1 is my poor man's fix for now, but that requires people to know that convention, so of course a built-in language feature would be the best!
In the documentation for component libraries like this one, they added a "Reactive" tag to the props that could be reactive, so that covers types 1 and 2, but not just 1.
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: