Open adiguba opened 4 hours ago
I wonder: there's a disadvantage in directly define those types this way? Obviously with a type argument to specify the children snippets arguments.
There's a related issue somewhere asking for snippet type being relaxed. That would solve most of these problems already. on:
and bind:
being present... Not sure what best to do here.
As shown it's somewhat straightforward to implement a helper type in user land, so let's wait for more use cases / upvotes first
Hello! My 2 cents is that children
should not exist in the base types. Sometimes we write components that allow no children. I think the component should be explicit about the existence children
by specifying it in its Props type.
Describe the problem
The module "svelte/elements" provides the definitions of HTML attributes that can be used to declare props to spread in a component that "wrap" a HTML element.
For example for a component
Button
, using directly the typeHTMLButtonAttributes
Or via the equivalent using
SvelteHTMLElements
But there are 2 flaws :
bind:
andon:
directives, which are therefore proposed by autocompletionIn order to remove the
bind:
/on:
directives, II need to write something like that :And if I need to specify a parameter for the children snippet, I have to write :
Describe the proposed solution
It would be nice if Svelte 5 had an official type to handle this in "svelte/elements".
Something like this might work :
So we can use
SvelteHTMLProps<'button'>
in order to define our Button component :Or
SvelteHTMLProps<'button', [number]>
to define the children parameter type :Importance
nice to have