Support custom events on native DOM elements
See original GitHub issueIs your feature request related to a problem? Please describe. I get the following error when I’m trying to add custom events on native DOM elements:
Type '{ onswipestart: (event: CustomEvent<any>) => void; onswipemove: (event: CustomEvent<any>) => void; onswipeend: (event: CustomEvent<any>) => void; style: string; class: string; }' is not assignable to type 'HTMLProps<HTMLDivElement>'.
Property 'onswipestart' does not exist on type 'HTMLProps<HTMLDivElement>'.ts(2322)
The custom events are dispatched to a div
element using Sveltes actions/use directive https://svelte.dev/examples#actions).
Describe the solution you’d like Be able to type check for custom events dispatched using Svelte actions on native DOM elements.
Describe alternatives you’ve considered I could try to convert the div to an individual Svelte component but preferably it should work on native DOM elements as well.
Additional context

This is how I listen to the custom events:
<div
class="bottomSheet"
class:draggable
bind:this={bottomSheet}
use:swipeable
on:swipestart={handleSwipeStart}
on:swipemove={handleSwipeMove}
on:swipeend={handleSwipeEnd}
style="height:{height};bottom:{bottom};transform:translateY({$coords.ty}px);"
>
Related Pull Request for custom events on Svelte components: https://github.com/sveltejs/language-tools/pull/303
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:16 (10 by maintainers)
Top Results From Across the Web
Creating and triggering events - MDN Web Docs - Mozilla
This article demonstrates how to create and dispatch DOM events. Such events are commonly called synthetic events, as opposed to the events ......
Read more >Custom events in JavaScript: A complete guide
In this tutorial, you can learn how to create custom events in JavaScript for your application to enhance the user experience.
Read more >Dispatching custom events - The Modern JavaScript Tutorial
Custom events can be used to create “graphical components”. ... Built-in event classes form a hierarchy, similar to DOM element classes.
Read more >Web Components API: Lifecycle Events and Custom Events
Native events are the main way we have to add interactivity on the web as we execute some code based on the user...
Read more >A Complete Guide To Custom Events In JavaScript - Medium
Native DOM events are cancelable by default so we can call event.preventDeafult() on it which will prevent the default action of the event...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Don’t know if there is a way to make it only applies to elements with the action. but you can make it globally available like this.
Thanks, letting the user explicitly type the action or explicitly choose when to fall back to
CustomEvent<any>
would probably be the best case scenario but the solution by @jasonlyu123 is good enough for me now. Thanks for the great work!