Skip to content

Handling multiple event handlers in components with typescript #12468

Answered by brunnerh
ananduremanan asked this question in Q&A
Discussion options

You must be logged in to vote
  • The types of props can be intersected with attribute definitions from svelte/elements, which include all the event handlers, in this case HTMLButtonAttributes so e.g. let { ... }: ButtonProps & HTMLButtonAttributes = $props();; alterniatevly define it as a separate type/make ButtonProps extend the attrbutes.
  • class can be aliased on destructuring if you need it as a separate property, but in your first example it would just be part of the rest object, i.e. rest.class.
    // aliasing a property:
    let { class: className } = $props();
    
    // if you don't need bindings, keeping a single object is also possible:
    let props = $props();

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ananduremanan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants