Interface Action<Element, Parameter, Attributes>
Type Parameters
- Element = HTMLElement
- Parameter = undefined
- Attributes extends Record<string, any> = Record<never, any>
- Action<Node>(
 ...args: undefined extends Parameter
 ? [node: Node, parameter?: Parameter]
 : [node: Node, parameter: Parameter],
 ): void | ActionReturn<Parameter, Attributes>
Actions are functions that are called when an element is created. You can use this interface to type such actions. The following example defines an action that only works on
<div>elements and optionally accepts a parameter which it has a default value for:Action<HTMLDivElement>andAction<HTMLDivElement, undefined>both signal that the action accepts no parameters.You can return an object with methods
updateanddestroyfrom the function and type which additional attributes and events it has. See interfaceActionReturnfor more details.Docs: https://svelte.dev/docs/svelte-action