parameter Class — svelte Architecture
Architecture documentation for the parameter class in index.d.ts from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 91aca5c5_c82b_4d36_0cbc_dd8cea61af3b["parameter"] 6bd9d090_a582_e05c_669e_d53d4e7245f2["index.d.ts"] 91aca5c5_c82b_4d36_0cbc_dd8cea61af3b -->|defined in| 6bd9d090_a582_e05c_669e_d53d4e7245f2 06be5c5b_255a_3ee9_6066_2d80e2197446["args()"] 91aca5c5_c82b_4d36_0cbc_dd8cea61af3b -->|method| 06be5c5b_255a_3ee9_6066_2d80e2197446
Relationship Graph
Source Code
packages/svelte/types/index.d.ts lines 604–676
declare module 'svelte/action' {
/**
* Actions can return an object containing the two properties defined in this interface. Both are optional.
* - update: An action can have a parameter. This method will be called whenever that parameter changes,
* immediately after Svelte has applied updates to the markup. `ActionReturn` and `ActionReturn<undefined>` both
* mean that the action accepts no parameters.
* - destroy: Method that is called after the element is unmounted
*
* Additionally, you can specify which additional attributes and events the action enables on the applied element.
* This applies to TypeScript typings only and has no effect at runtime.
*
* Example usage:
* ```ts
* interface Attributes {
* newprop?: string;
* 'on:event': (e: CustomEvent<boolean>) => void;
* }
*
* export function myAction(node: HTMLElement, parameter: Parameter): ActionReturn<Parameter, Attributes> {
* // ...
* return {
* update: (updatedParameter) => {...},
* destroy: () => {...}
* };
* }
* ```
*/
export interface ActionReturn<
Parameter = undefined,
Attributes extends Record<string, any> = Record<never, any>
> {
update?: (parameter: Parameter) => void;
destroy?: () => void;
/**
* ### DO NOT USE THIS
* This exists solely for type-checking and has no effect at runtime.
* Set this through the `Attributes` generic instead.
*/
$$_attributes?: 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:
* ```ts
* export const myAction: Action<HTMLDivElement, { someProperty: boolean } | undefined> = (node, param = { someProperty: true }) => {
* // ...
* }
* ```
* `Action<HTMLDivElement>` and `Action<HTMLDivElement, undefined>` both signal that the action accepts no parameters.
*
* You can return an object with methods `update` and `destroy` from the function and type which additional attributes and events it has.
* See interface `ActionReturn` for more details.
*/
export interface Action<
Element = HTMLElement,
Parameter = undefined,
Attributes extends Record<string, any> = Record<never, any>
> {
<Node extends Element>(
...args: undefined extends Parameter
? [node: Node, parameter?: Parameter]
: [node: Node, parameter: Parameter]
): void | ActionReturn<Parameter, Attributes>;
}
// Implementation notes:
// - undefined extends X instead of X extends undefined makes this work better with both strict and nonstrict mode
export {};
}
Defined In
Source
Frequently Asked Questions
What is the parameter class?
parameter is a class in the svelte codebase, defined in packages/svelte/types/index.d.ts.
Where is parameter defined?
parameter is defined in packages/svelte/types/index.d.ts at line 604.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free