You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently if we use an on:event on a DOM element :
<buttonon:click={click}> label </button>
we have either a warning or a error depending on whether or not other new event handlers are used :
warning : Using on:click to listen to the click event is deprecated. Use the event attribute onclick
error : Mixing old (on:click) and new syntaxes for event handling is not allowed. Use only the onclick
And that's just fine.
...
But it's not the same for components, where all the on:event are silently accepted, even if they will be completely ignored :
<MyButtonon:click={click}> label </MyButton> <!-- no warn/error -->
It's even worse if we have strongly typed our component with the types defined in evelte/elements, since the on:event will then be proposed by the autocompletion (same thing for the and element's bind:prop)
I think that Svelte should produce a warning when an on:event is used on a component, at least in runes mode.
This will avoid mistakes when migrating code...
And (if possible) an error if the Component is in Svelte 5 and do no use createEventDispatcher()...
Bonus : svelte/elements should define element's types without the on:event/bind:prop.
Even though there is a possible (but verbose) solution for that with Typescript Template Literal Types :
We're not warning because if that component is not under your control (i.e. from a library) you may have no control over updating it, so you get unactionable warnings. We could warn on createEventDispatcher usage in runes mode though
Describe the problem
Hello,
Currently if we use an
on:event
on a DOM element :we have either a warning or a error depending on whether or not other new event handlers are used :
And that's just fine.
...
But it's not the same for components, where all the
on:event
are silently accepted, even if they will be completely ignored :It's even worse if we have strongly typed our component with the types defined in
evelte/elements
, since theon:event
will then be proposed by the autocompletion (same thing for the and element'sbind:prop
)Describe the proposed solution
I think that Svelte should produce a warning when an
on:event
is used on a component, at least in runes mode.This will avoid mistakes when migrating code...
And (if possible) an error if the Component is in Svelte 5 and do no use
createEventDispatcher()
...Bonus :
svelte/elements
should define element's types without theon:event
/bind:prop
.Even though there is a possible (but verbose) solution for that with Typescript Template Literal Types :
Importance
nice to have
The text was updated successfully, but these errors were encountered: